Cannot load Exchange powershell snap-in: The type initializer for 'Microsoft.Exchange.Data.Directory.Globals' threw an exception

╄→尐↘猪︶ㄣ 提交于 2019-12-03 11:23:14

After further investigation I figured out that .NET 4.5 is an in place update meaning that .NET 4.0 is overwritten and replace with .NET 4.5 when installed. I don't know what changed in .NET 4.5 that causes this but the issue is resolved by uninstalling .NET 4.5 and switching back to Visual Studio 2010. Hopefully Microsoft will have some update in the near future that will resolve the issue and allow me to use Visual Studio 2012 again.

See the following article for more info about the in place update. http://www.devproconnections.com/article/net-framework/net-framework-45-versioning-faces-problems-141160

It appear to be a know bug. There is a Microsoft connect report:

https://connect.microsoft.com/VisualStudio/feedback/details/770748/powershell-exception-after-4-5-upgrade#tabs

Microsoft's response is that they have "logged [the] issue with the Exchange team"

As a workaround you can do one of the following:

  • Uninstall .NET 4.5
  • Change the your application's target framework to 2.0 or 3.5.

I have investigated the actual bug in the Microsoft Exchange assemblies, and the problem was the ExTraceConfiguration class (internal) from the Microsoft.Exchange.Diagnostics.dll assembly enumerates all loaded assemblies in the current app domain. If it finds System.IdentityModel or System.ServiceModel, it uses reflection to configure some tracing for them. But the reflection code is not compatible with the .net 4.5 ServiceModel and an error occurs. After the error is detected (a null condition is checked) a trace is tried, but the code is currently in the process of configuring tracing so => hard crash.

The solution is to use reflection on the Microsoft.Exchange.Diagnostics.dll, load up the ExTraceConfiguration type and run it's type initializer:

type.TypeInitializer.Invoke(null, null);

before System.ServiceModel has had a chance to load yet in your app domain. This initializer is a static constructor which can only run once per process, so after that you are safe to load ServiceModel if you need it.

I have exactly the same issue with the same error output with my production server. However, I have a test server with the same configuration using .Net 4.5 framework but not having this issue. So i dont think uninstalling .Net 4.5 will resolve my issue.

My solution is I've found that in the production server ASP.Net Impersonation setting in IIS was enabled.

After i disable it, my powershell runspace can be created, the "Microsoft.Exchange.Management.PowerShell.E2010" snapin can be added an my application is working fine!

Seems like it having some sort of a permission issue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!