1

我正在尝试使用以下代码连接到另一台计算机:

String FullComputerPathName = @"\\mycomputer\";

ConnectionOptions options = new ConnectionOptions();
options.Password = "some_password";
options.Username = "some_user";

ManagementScope scope = new ManagementScope(FullComputerPathName, options);
scope.Connect();

并得到了例外:

“System.Management.WmiNetUtilsHelper”的类型初始化程序引发了异常。内部异常:ArgumentNullException:值不能为空。

日志跟踪:

“在 System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer(IntPtr ptr,类型 t)

在 System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer[TDelegate] (IntPtr ptr)

在 System.Management.WmiNetUtilsHelper.LoadDelegate[TDelegate](TDelegate&delegate_f, IntPtr hModule,String procName)

在 System.Management.WmiNetUtilsHelper...cctor()"

我不明白出了什么问题。

谢谢

4

1 回答 1

1

我刚刚在 2008 R2 上遇到了同样的问题。

tl;dr:安装最新版本的 .net 框架(安装 4.7 对我有用)

更长的版本:我假设您Microsoft.Windows.Compatibility在 .net 核心项目中使用。

反编译System.Management.dll程序集后,我发现它正在寻找.net框架路径,并且正在使用该文件v4.0.30319/wminet_utils.dll并正在加载50个方法,但如果没有找到,它会失败。就我而言,它丢失了"GetErrorInfo"并且"Initialize".

我不知道我有哪个 .NET 框架版本,但更新到 4.7 解决了我的问题。

于 2019-07-11T13:45:35.290 回答