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

System.Management.dll not working on win-arm64 #81400

Closed
SteveL-MSFT opened this issue Jan 31, 2023 · 27 comments · Fixed by #83522
Closed

System.Management.dll not working on win-arm64 #81400

SteveL-MSFT opened this issue Jan 31, 2023 · 27 comments · Fixed by #83522

Comments

@SteveL-MSFT
Copy link
Contributor

SteveL-MSFT commented Jan 31, 2023

Description

This dll works on x64, but fails to load the required native dll on win-arm64. This is impacting the Get-HotFix cmdlet in PowerShell 7.

Reproduction Steps

var scope = new System.Management.ManagementScope(@"root\cimv2");
scope.Connect();

Expected behavior

No error (nothing will happen with this snippet)

Actual behavior

It appears to be trying to load the native library from Framework64 when it should be loading it from FrameworkArm64:

Unhandled exception. System.TypeInitializationException: The type initializer for 'System.Management.WmiNetUtilsHelper' threw an exception.
 ---> System.ComponentModel.Win32Exception (193): Failed to load required native library 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\wminet_utils.dll'.
   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)
   at System.Management.ManagementPath..ctor(String path)
   at System.Management.ManagementScope..ctor(String path)
   at Program.<Main>$(String[] args) in C:\Users\slee\test\wmi\Program.cs:line 1

Regression?

Don't know

Known Workarounds

No response

Configuration

.NET 7
Windows 11
arm64

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jan 31, 2023
@ghost
Copy link

ghost commented Jan 31, 2023

Tagging subscribers to this area: @dotnet/area-system-management
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

This dll works on x64, but fails to load the required native dll on win-arm64. This is impacting the Get-HotFix cmdlet in PowerShell 7.

Reproduction Steps

var scope = new System.Management.ManagementScope(@"root\cimv2");
scope.Connect();

Expected behavior

No error (nothing will happen with this snippet)

Actual behavior

Unhandled exception. System.TypeInitializationException: The type initializer for 'System.Management.WmiNetUtilsHelper' threw an exception.
---> System.ComponentModel.Win32Exception (193): Failed to load required native library 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\wminet_utils.dll'.
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)
at System.Management.ManagementPath..ctor(String path)
at System.Management.ManagementScope..ctor(String path)
at Program.

$(String[] args) in C:\Users\slee\test\wmi\Program.cs:line 1

Regression?

Don't know

Known Workarounds

No response

Configuration

.NET 7
Windows 11
arm64

Other information

No response

Author: SteveL-MSFT
Assignees: -
Labels:

area-System.Management

Milestone: -

@smasher164
Copy link
Member

Could be related: #59844

/cc @ericstj @danmoseley

@ViktorHofer
Copy link
Member

ViktorHofer commented Feb 6, 2023

We probably need to update the lookup code that finds the .NET Framework installation (kudos to @ericstj):

RegistryKey netFrameworkSubKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\.NETFramework\");

@ViktorHofer ViktorHofer added this to the 8.0.0 milestone Feb 6, 2023
@ViktorHofer ViktorHofer removed the untriaged New issue has not been triaged by the area owner label Feb 6, 2023
@ericstj
Copy link
Member

ericstj commented Feb 6, 2023

If possible, we should also re-enable tests on ARM64 while doing this.

PlatformDetection.IsNotArmNorArm64Process &&

This wasn't possible in the past when we didn't have an ARM64 .NETFramework. Now that we do, we should make it work 👍

@ericstj
Copy link
Member

ericstj commented Feb 9, 2023

This is likely not a regression, but rather something that never worked but can now that we have an Arm64 .NET Framework. @SteveL-MSFT how urgent is a fix here?

@SteveL-MSFT
Copy link
Contributor Author

@ericstj I don't think it's super urgent, but the original issue was reported by a customer. If it can be addressed within the next couple of months, I think that would be fine.

@SimonCropp
Copy link
Contributor

@Nuklon
Copy link

Nuklon commented Feb 27, 2023

Can't we ship that DLL with .NET Core instead? It would be much better than relying on .NET Framework being installed.

@SimonCropp
Copy link
Contributor

SimonCropp commented Feb 27, 2023

@SteveL-MSFT

I don't think it's super urgent, but the original issue was reported by a customer. If it can be addressed within the next couple of months, I think that would be fine.

Note this was actually reported in Oct 2021 in 59844. so a "couple of months" has definitely passed

@JamesWCCheng
Copy link

I also encountered this problem by using the latest

[Experimental change]
If I set registry InstallRoot from C:\Windows\Microsoft.NET\Framework64\ to C:\Windows\Microsoft.NET\FrameworkArm64\

ARM64 process with WMI works fine.

I think it's a simple change, I'm looking forward to seeing it gets fixed soon.

@JamesWCCheng
Copy link

I also encountered this problem by using the latest

[Experimental change] If I set registry InstallRoot from C:\Windows\Microsoft.NET\Framework64\ to C:\Windows\Microsoft.NET\FrameworkArm64\

ARM64 process with WMI works fine.

I think it's a simple change, I'm looking forward to seeing it gets fixed soon.

.netframework has no such issue since it wrote
System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() + "\wminet_utils.dll";
https://referencesource.microsoft.com/#System.Management/managementscope.cs,304
to compose the path. But this API didn't fit .net core.

Can Microsoft fix it as soon as possible? It's a critical issue I think, it makes this package malfunction.

@ViktorHofer
Copy link
Member

We understand the importance here which is why I'll be working on a fix for this next week. After the fix is merged into main, we plan to backport it into .NET 6 and .NET 7.

@SimonCropp
Copy link
Contributor

@ViktorHofer can it be backported to the v6 System.Management nuget? i still support netcore 3.1 since it only went "End of support" 4 month ago

Please

@ViktorHofer
Copy link
Member

ViktorHofer commented Mar 9, 2023

Yes, the plan is to backport the fix into both the 6.0 and 7.0 nuget package but a) we don't yet have a fix ready and b) our shiproom needs to first approve the backports.

Note that while .NET 6 package provide a netcoreapp3.1 assembly, that runtime is already out-of-support and we strongly discourage staying on it or offering assets for it because of the lack of security fixes.

@SimonCropp
Copy link
Contributor

@ViktorHofer

the plan is to backport the fix into both the 6.0 and 7.0 nuget package

thanks. thats great to hear

that runtime is already out-of-support and we strongly discourage staying on it or offering assets for it because of the lack of security fixes

i hear you. but i still have a non-trivial number of people using my libs that are still on unsupported frameworks VerifyTests/Verify#784

@Nuklon
Copy link

Nuklon commented Mar 9, 2023

Can't we ship that DLL with .NET Core instead? It would be much better than relying on .NET Framework being installed.

Thanks, but what about shipping the necessary DLL with Runtime? That'd be better as it would avoid the need to have .NET Framework installed.

@ViktorHofer
Copy link
Member

Thanks, but what about shipping the necessary DLL with Runtime? That'd be better as it would avoid the need to have .NET Framework installed.

From my discussion with @ericstj, there was a very strong reason to not bundle that assembly into the package but I don't remember. @ericstj would you mind sharing some context here?

@ViktorHofer ViktorHofer self-assigned this Mar 13, 2023
@ericstj
Copy link
Member

ericstj commented Mar 13, 2023

WMINet_utils is a native binary and I believe requires machine-wide registration/installation to work correctly. It also has never been open sourced, so it would need to go through that process. On top of that the component isn't owned by .NET so it would require some help/permission from the owning team to see that happen assuming such a port was even possible. That's all out of the scope of this issue and tracked by #66386.

@Dharmateja-Challa-Dell
Copy link

I have done few changes as per previous comments, enabled unit test for ARM64, added one test case for this particular issue. Not sure if this solution is correct or not, hence wanted to check, attaching my changes and unit test case and its results in both ARM64 and X64
.NetCore81400.zip

@ViktorHofer
Copy link
Member

@Dharmateja-Challa-Dell I won't open you attachment. Can you please let me know what your comment refers to?

@danmoseley
Copy link
Member

@Dharmateja-Challa-Dell if you want to share a proposed change please do it by pushing a branch to your fork and sending a link to that.

@Silve2611
Copy link

This is also a critical error for us. When can we expect for that it will be resolved? Do you have a timeframe?

@Dharmateja-Challa-Dell
Copy link

@Dharmateja-Challa-Dell if you want to share a proposed change please do it by pushing a branch to your fork and sending a link to that.
Took a fork and added changes to branch
https://github.com/Dharmateja-Challa-Dell/runtime/branches/

@ViktorHofer
Copy link
Member

ViktorHofer commented Mar 15, 2023

Do you have a timeframe?

As shared above, I'll be working on a fix this week and we will then bring it to our shiproom for backport approval. I can't share when this would then be available but likely not before May.

EDIT: We got this into the April servicing release so updated packages with the change will be available mid April.

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Mar 16, 2023
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Mar 16, 2023
@SimonCropp
Copy link
Contributor

was this included in v6.0.1? https://www.nuget.org/packages/System.Management/6.0.1

@ViktorHofer
Copy link
Member

ViktorHofer commented Apr 12, 2023

Yes, the fix is part of the following package versions:

@SimonCropp
Copy link
Contributor

@ViktorHofer thanks

@ghost ghost locked as resolved and limited conversation to collaborators May 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants