Cannot load Exchange powershell snap-in on .NET 4.0: The type initializer for Microsoft.Exchange.Data.* threw an exception - .net-4.0

I have recently upgraded my application from .NET framework 2.0 to .NET 4.0. I am facing a strange problem after upgrade. I am unable to load Microsoft Exchange/Powershell Assemblies.
rc = RunspaceConfiguration.Create(); warning = null;
if (Version == "2010")
info = rc.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.E2010", out warning);
One of the exceptions are:
[Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.][1]
The code works absolutely fine in .NET 2.0. I am unable to understand the cause of the problem. But with reference to this article,I have concluded that this is a bug. Please suggest the soultion.
Thanks in advance

I think that you may be encountering the same issue as:
Cannot load Exchange powershell snap-in: The type initializer for 'Microsoft.Exchange.Data.Directory.Globals' threw an exception
Do you have .NET 4.5 installed? It apparently overwrites .NET 4.0 and causes issues with the Exchange cmdlets. The above post fixed the issue by uninstalling .NET 4.5 and installing .NET 4.0.
Hope this helps!

Related

Could not load file or assembly 'System.Diagnostics.DiagnosticSource on ASP.Net Core migration from VS2015 to VS2017

I have a web in ASP.Net Core (4.6.1 framework) that uses Facebook and MS external login that I created with Visual Studio 2015 and opened in the new Visual Studio 2017 that came out yesterday. VS2017 made a few changes related to the csproj, project.json, etc files.
The site compiled and executed fine except for one part. If I did a Facebook or Microsoft external login, the site displayed this trap:
FileLoadException: Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
System.Net.Http.WinHttpHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
AggregateException: Unhandled remote failure.
Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler+<HandleRemoteCallbackAsync>d__6.MoveNext()
The url in the browser showed that it was attempting to return from the external login to the local (https://localhost:44321/signin-facebook?code=... or /signin-microsoft).
The version number of the System.Diagnostics.DiagnosticSource.dll (and System.Net.Http.dll) is 4.6.24705.1.
I started a new VS2017 project from scratch with Facebook and MS login added and it worked fine - getting me logged on without the trap. The dll's were the same versions.
Comparing the two csproj files showed differences but nothing obvious (nothing related to System dlls):
What solved it for me was to add a NuGet reference to System.Net.Http (version 4.3.1) to the newly migrated project.
https://www.nuget.org/packages/System.Net.Http/
The recommended answer did not resolve my issue. I was getting this error when trying to reference a .Net 4.6.2 lib in a .Net Core 2 project.
To resolve the issue I had to add the Microsoft.Windows.Compatibility nuget package.
Credit to: https://medium.com/#ans_ashkan/asp-net-core-and-windows-event-log-75770a80a666
In References 'System.Diagnostics.DiagnosticSource' not included in solution
On installing latest version "5.0.1" of 'System.Diagnostics.DiagnosticSource' in NUget solved my issue. Hope it will fix yours also.
I had the same issue and weirdly enough, problem resolved with updating Microsoft.ApplicationInsights versions. 2.20.0 is the version to go (for me). I don't know the connection between these packages but that's what happened.
People using .NET Core web applications monitored with Application Insights hosted in App Services facing this issue
This when .NET Core web application has a dependency on 'System.Diagnostics.DiagnosticSource%u2019 binary and has this binary file deployed to /wwwroot/ folder, which is rare.
Work Around: Please set previous version of monitoring extension by changing this app setting if you experience the above issue: ApplicationInsightsAgent_EXTENSIONVERSION=2.8.24
After doing this please restart the application.
Here is the source

Could not load file or assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35'

In Visual Studio 2012 I created an ASP.NET MVC 4 project where the target framework is the .NET Framework 4.5. When I deployed my project to a web server it gave the following error:
Could not load file or assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file
specified.
Description: An unhandled exception occurred during the execution of the current web request.
Please review the stack trace for more information about the error and where
it originated in the code.
Exception Details: System.IO.FileNotFoundException: Could not load file or
assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
The system cannot find the file specified.
Source Error:
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34237
I had the same issue today during deployment. I was able to fix it by marking the assembly to be copied to the deployment file.
In order to do this, in my Visual Studio project, select the System.Web.Http.Webhost assembly in your references and alter the 'Copy Local' property to True. I had to repeat this for a few other assemblies that were missing.
Thanks to this website for the tips - http://haacked.com/archive/2008/11/03/bin-deploy-aspnetmvc.aspx/
Check the bin folder of your deployed project. It should contain System.Web.Http.WebHost.dll.
If this dll is in this folder, check it version. If it isn't 4.0.0.0, then you should deploy version 4.0.0.0 or change your web config to use other version (not really good idea because of dependencies)
Try to reinstall Microsoft.AspNet.WebApi package. Open Package Manager Console and type:
Update-Package Microsoft.AspNet.WebApi -reinstall
Be careful, this command will remove all dependencies and you will have to install them manually.
I had this error with an old project that I was going back to do a bit of work on. It turns out the project wasn't actually using WebApi so I uninstalled Microsoft.AspNet.WebApi using NuGet. That solved the problem for me.
If I'd actually have needed WebApi I'm sure installing it again would have fixed the error too.
I ran into this today after setting up a new Team City Build Agent. The new agent didn't have MVC 4 installed, perhaps part of the problem. Fortunately, I found this article which lead me to the solution. In Team City, I just updated the Build Step for the Nuget Restore so that it doesn't use the local cache.
This works because the cache may have been established by build runners with different (MVC) frameworks installed already.
I know this is answered but I thought I'd add something.
Every time I set "copy local" to true on a file causing the error I'd publish it and just get another one. So I just selected all of the files under references and set them all to true. This fixed the issue for me.
Important: This error message can be caused because you are deploying a 4.5 project to a server that doesn't have 4.0 installed. Make sure you have the .NET Framework version installed in IIS for the project you need. Some of these DLLs by default won't copy up, because it uses the core project DLL normally. Check to make sure your production server has the .NET version you're going with. I experienced this myself with a 4.5 project on a 4.0 server.
Ensure ASP.NET MVC 4 is installed on your server. Check it in the following location -
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4

How do I stop Ninject for WebApi failing on "var kernel = new StandardKernel();"

I just installed Ninject.MVC5 into my solution (I have an MVC project and a WebApi project in there and I wanted Ninject for both).
Then I installed WebApiContrib.IoC.Ninject to build on the previous install so that I could use Ninject in the WebApi package.
Then I updated the packages (because NuGet showed updates to install - even though I had updated the packages directly prior to installing Ninject).
I tried running my WebApi project but it failed on var kernel = new StandardKernel(); in NinjectWebCommon.CreateKernel() with this error:
An exception of type 'System.IO.FileNotFoundException' occurred in Ninject.dll but was not handled in user code
Additional information: Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Having read several answers on here and contemplated certain relatively complex solutions I tried one more thing which I will share in the Answer in case it helps anyone else...
I removed WebApiContrib.IoC.Ninject from the WebApi project (via NuGet: Manage and then untick to remove) and then added it back.
Project runs and behaves as expected, and no updates are required after adding WebApiContrib.IoC.Ninject back in to WebApi project.
The update that NuGet identified as required overwrote/broke something that was fixed by this answer.
Add the package Microsoft.Aspnet.Mvc from Nuget.
Solved for me.
In my case, MVC4 for Framework 4.0 and Visual Studio 2017

.Net Reflector crash

I have problem with my .Net Reflector 8.3 application. When I double click it doesn't start and generates error.
.Net Reflector has just thrown an exception: Could not load file or assembly '{a755eaf2-c07e-4b95-b1ee-a3437dfa4635}', PublicKeyToken=3e56350693f7355e' or one of its dependencies. The system cannot find the file specified.
I am using Windows 8.0 x64. I've also enabled .Net framework 3.5 and 4.5.1 installed on my machine. I've searched every where and find nothing to solve.
Thanks in advance.

Getting error in umbraco The type or namespace name 'Umbraco' could not be found

The type or namespace name 'Umbraco' could not be found (are you
missing a using directive or an assembly reference?)
I am getting this error when I am inheriting my controller from
Umbraco.Web.Mvc.RenderMvcController
I have checked that umbraco.dll is referenced when I install umbraco from NuGet in Visual Studio 2012.
Intellisense allow me to select this reference but when I compile code it throw this exception like below screen explains it.
All other umbraco is working nice I have designs some static views, master pages, macros etc. all working fine.
In case of Umbraco.
my application was on .Net FrameWork 4.0
umbraco previous version was using .Net FrameWork 4.0
so i was try to use new release of Umbraco 7.0.1 on same FrameWork 4.0 after reading an post i check for .Net Framework for new release i found that was on .Net FrameWork 4.5 so i upgraded my application to 4.5 it resolve the issue.
thanks to everyone who visit to this post.