1
votes

I'm trying to connect to another computer using this code:

String FullComputerPathName = @"\\mycomputer\";

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

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

And got the exception:

The type initializer for 'System.Management.WmiNetUtilsHelper' threw an exception. Inner Excepction: ArgumentNullException: value cannot be null.

The log trace:

"at System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer(IntPtr ptr, Type t)

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

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

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

I don't understand what went wrong .

Thank you

1
Please show the full stack trace - that's likely to help work out what's going on. - Jon Skeet
@DaisyShipton I added the full stack trace. - shani klein
That doesn't show the stack trace for the inner exception, which would give more information about what shouldn't be null. Basically include everything you can from the log. - Jon Skeet

1 Answers

1
votes

I just came across the same issue on 2008 R2.

tl;dr: Install a recent version of the .net framework (installing 4.7 worked for me)

Longer version: I'm assuming that you are using Microsoft.Windows.Compatibility in a .net core project.

After decompiling the System.Management.dll assembly, I found that it is looking for the .net framework path, and is using the file v4.0.30319/wminet_utils.dll and is loading 50 methods, but if one is not found, it fails. In my case, it was missing "GetErrorInfo" and "Initialize".

I don't know which .NET framework version I had, but updating to 4.7 solved my issue.