我有以下代码创建一个Power
Shell运行空间,并加载了Exchange 2010快照.
原文链接:https://www.f2er.com/windows/369203.htmlDim runspaceConfig = RunspaceConfiguration.Create() Dim snapInException As PSSnapInException = Nothing runspaceConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.E2010",snapInException) Dim runspace = RunspaceFactory.CreateRunspace(runspaceConfig) runspace.Open()
自从安装Visual Studio 2012以来,在执行将管理单元添加到runspace配置中的行时,我开始收到以下错误.
System.Management.Automation.Runspaces.PSSnapInException occurred HResult=-2146233087 Message=Cannot load Windows PowerShell snap-in Microsoft.Exchange.Management.PowerShell.E2010 because of the following error: The type initializer for 'Microsoft.Exchange.Data.Directory.Globals' threw an exception. Source=System.Management.Automation WasThrownFromThrowStatement=False StackTrace: at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadCustomPSSnapIn(PSSnapInInfo mshsnapinInfo) at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadPSSnapIn(PSSnapInInfo mshsnapinInfo) at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadPSSnapIn(PSSnapInInfo mshsnapinInfo,PSSnapInException& warning) at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.DoAddPSSnapIn(String name,PSSnapInException& warning) at System.Management.Automation.Runspaces.RunspaceConfiguration.AddPSSnapIn(String name,PSSnapInException& warning)
我已经能够确认nlog是不知何故导致这个问题.在创建powershell runspace之前创建一个nlog记录器的组合会导致错误.
如果我从我的应用程序配置中删除nlog配置部分,只需创建一个空的nlog记录器,那么加载中没有错误.另外,如果我在应用程序配置中留下了nlog配置,但是不创建一个nlog记录器,那么管理单元也被成功加载.
>我已经尝试在x64和x86中构建项目.
>我已经重新安装了交换管理工具.
>我已经尝试在交换环境中的另一台机器上进行测试.
如果有人可以提供任何可能帮助我解决这个问题的建议,我将会很有意思.
谢谢