首页 > 解决方案 > “WSMan 初始化失败,错误代码:-2144108171”错误

问题描述

我有 MVC Web 应用程序控制器来使用以下代码连接 Exchange 服务器 powershell:

  enter connectionInfo = new WSManConnectionInfo(new Uri(ConfigurationManager.AppSettings.Get   ("WSManConnectionInfo").ToString()), "http://schemas.microsoft.com/powershell/Microsoft.Exchange",  newCred);
        connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
string rspace = "space is OK";
        try
        {
            //--create remote runspace
            runspace = RunspaceFactory.CreateRunspace(connectionInfo);
        } catch (Exception ex2)
        {
            rspace = ex2.Message.ToString();
        }
        ViewBag.rspace = rspace; //show the above error message on client side view

以上代码在我的本地机器上运行良好,但在发布到生产服务器后出现上述错误,请注意我可以看到生产服务器的 bin 文件夹中存在“Microsoft.Management.Infrustructure.dll”。

请告知如何解决此错误,非常感谢,

编辑:我什至尝试添加这 3 行代码,但同样的错误;

连接信息.SkipCACheck = true;

连接信息.SkipCNCheck = true;

connectionInfo.MaximumConnectionRedirectionCount = 4;代码在这里

编辑: System.Management.Automation.dll 也被添加到 Reference 文件夹中

标签: c#asp.netweb-servicesmodel-view-controllerpowershell-2.0

解决方案


看来问题已经解决了,我认为是 System.Management.Automation 安装引起的,这就是我所做的:

1.首先确保将 System.Management.Automation.dll 添加到 C:\windows\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf3856ad364e35\System.Management.Automation.dll 的 References 文件夹中,这个 dll文件在那里,但它仍然导致错误,

2.转到Manage Nuget包并从那里安装System.Management.Automation,虽然它们具有相同的名称,但我认为这个文件与第一步添加的System.Management.Automation.dll不同。但安装此文件后,问题就消失了。C# 代码没有任何变化,


推荐阅读