Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Microsoft.Windows.CompatibilityPack WMI exception #27001

Closed
jjxtra opened this issue Jul 28, 2018 · 14 comments
Closed

Microsoft.Windows.CompatibilityPack WMI exception #27001

jjxtra opened this issue Jul 28, 2018 · 14 comments

Comments

@jjxtra
Copy link

jjxtra commented Jul 28, 2018

System.Management throws a strange exception, but only on some Windows machines, other machines are just fine. Issue is here: https://stackoverflow.com/questions/50444876/type-initializer-for-system-management-wminetutilshelper-threw-an-exception...

The type initializer for 'System.Management.WmiNetUtilsHelper' threw an exception. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: ptr
   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()
   --- End of inner exception stack trace ---
   at System.Management.MTAHelper.IsNoContextMTA()
   at System.Management.MTAHelper.CreateInMTA(Type type)
   at System.Management.ManagementPath.CreateWbemPath(String path)

This is in self-contained x86 Windows, .NET core 2.1, on Windows Server 2012 R2 x64. SQL 2014 also installed. Another identical server without SQL 2014 does not have the error.

Could this be related to wminet_utils.dll missing?

Any ideas where to start looking?

@jnm2
Copy link
Contributor

jnm2 commented Jul 28, 2018

/cc @ericstj

@jjxtra
Copy link
Author

jjxtra commented Jul 28, 2018

It's not the TrimUnusedDependencies property after all. Problem exists even with it as false.

@jjxtra
Copy link
Author

jjxtra commented Jul 28, 2018

This code works on the same machine with the failure:

string tempFile = Path.GetTempFileName();
StartProcessAndWait("cmd", "/C wmic path Win32_OperatingSystem get Caption,Version > \"" + tempFile + "\"");
string[] lines = File.ReadAllLines(tempFile);
File.Delete(tempFile);
if (lines.Length == 2)
{
    int versionIndex = lines[0].IndexOf("Version");
    Name = lines[1].Substring(0, versionIndex - 1).Trim();
    Version = lines[1].Substring(versionIndex).Trim();
}

@danmoseley
Copy link
Member

I do not understand how this callstack is possible because ptr is checked for null already, here:
https://github.com/dotnet/corefx/blob/dfa1338034a24eacda7a89d63363ab267a603449/src/System.Management/src/System/Management/ManagementScope.cs#L385-L386
I recommend that you attach a debugger and debug what is going on there. Is the pointer somehow changing from not null to null?

@jjxtra
Copy link
Author

jjxtra commented Jul 29, 2018

@danmosemsft Comparing IntPtr to null should not be possible as IntPtr is a struct, but perhaps the == operator comes into play some how? This feels like a compiler quirk or hack. At any rate, it always returns false, even for IntPtr.Zero. See the following code:

IntPtr ptr1 = IntPtr.Zero;
IntPtr ptr2 = new IntPtr(1);
bool ptr1Null = (ptr1 == null); // false
bool ptr2Null = (ptr2 == null); // false
bool ptr1Zero = ptr1 == IntPtr.Zero; // true
bool ptr2Zero = ptr2 == IntPtr.Zero; // false

@jjxtra
Copy link
Author

jjxtra commented Jul 29, 2018

@jjxtra
Copy link
Author

jjxtra commented Jul 29, 2018

Issue logged: dotnet/corefx#31456

@danmoseley
Copy link
Member

Oh! - you're right @jjxtra -- I didn't notice it was IntPtr. Yes, that's a bug. I put up a PR.

You'll still have to debug, to see which export is missing. Also where it is finding wminet_utils.dll. And what is the version of that file. We find it in the .NET framework. On my machine, it is

\Windows\Microsoft.NET\Framework\v4.0.30319\WMINet_Utils.dll
        FileVer:        00040007:0bf00000 (4.7:3056.0)
        ProdVer:        00040000:766f0000 (4.0:30319.0)

I have .NET 4.7.2

@pjanotti
Copy link
Contributor

Hi @jjxtra do you have more info about a repro of this issue? I suspect something went wrong with the Fx install (or its registry).

@jjxtra
Copy link
Author

jjxtra commented Aug 15, 2018

Sadly no, the customer only said it was server 2012 standard with sql server 2014 installed. I've never seen it myself personally. I switched to using wmic in https://github.com/jjxtra/IPBan but even wmic seems to fail on some Windows 7 home editions according to my analytics...

@pjanotti
Copy link
Contributor

Thanks for looking @jjxtra - I'm closing the issue for now since it is not actionable at this moment but get back to us if you get more info on it.

@theimowski
Copy link
Contributor

theimowski commented May 24, 2019

I'd like to revisit this one
Experienced same issue for self contained .NET Core 2.1 console app on Windows 8.1 Pro with .NET 4.5.1:

The type initializer for 'System.Management.WmiNetUtilsHelper' threw an exception. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: ptr

When I update System.Management to latest preview version (4.6.0-preview5.19224.8), the exception changes to:

System.PlatformNotSupportedException: The native library 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\wminet_utils.dll' does not have all required functions. Please, update the .NET Framework.

which is obviously more informative, however .NET Core is supposed to support Windows 8.1 OOTB.
Is this a known issue, or a "won't fix" due to one actually needs recent full .NET Framework to use System.Management?

@pjanotti could you please give some guidance on this?

@danmoseley
Copy link
Member

@theimowski could you please open a new issue? It is easy to overlook contents on old ones.

It doesnt surprise me this fails as we snapped WMI code from after this point. I guess they made code changes since 4.5.1 that require new exports. If you want you could debug a bit and see whether it's something minor and we could make our code tolerant of its absence.

@datoml
Copy link

datoml commented Aug 9, 2019

Sorry for open up the discussion here.
Just wanted to say that I had the same problem with .NET Framework 4.6.1.
After installing .NET Framework 4.7.2 it was working without any error.

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 3.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants