c# - “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 文件夹中
解决方案
看来问题已经解决了,我认为是 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# 代码没有任何变化,
推荐阅读
- javascript - 通过 Javascript 在 Qml 中更改时,字符串的结尾被截断
- android - 如何通过我的 Android 应用设置设备时间
- django - 如何根据 django 中的 pk 使用一个值预先填充文本字段
- android - Jetpack workmanager 不返回成功
- laravel - 调用未定义的方法“连接”
- java - Springboot中的@Value返回null
- typescript - 类型中缺少索引签名
- oracle - 引用 where 子句中选择列的值:Oracle
- elasticsearch - 是否可以使用 ElasticSearch.Net 或 Nest 进行动态响应
- c# - xpath 定位器 c# 正确的查找技术