Skip to content

System.Management has a dependency on .NET Framework #66386

Open

Description

@Symbai

Description

I've ported an application to .NET 6 and added nuget package of System.Management. It shows .NET 6 as supported, it depends on System.Codedom which also shows .NET 6 support. Apart of that no other dependencies. I've published my app as self-contained and ran it on a Windows 8.1 machine. It crashed and the event viewer got an entry saying:

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.

Reproduction Steps

Create a new .NET 6 project
Add System.Management nuget package
Publish self contained
Run on a machine with an outdated .NET framework

Expected behavior

I've expected that because its .NET6 and because it's self contained that it "just works" and that it does not depend on any .NET Framework installation. If it requires any additional native files, it should copy these to the publish folder of the .NET 6 self contained app.

Actual behavior

Application crashes, because it depends on (a specific) .NET Framework (version)

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Activity

  1. ghost added
    untriaged
    on Mar 9, 2022
  2. stephentoub commented on Mar 9, 2022

    @stephentoub
    Member

    Duplicate of #45143
    cc: @danmoseley, @ericstj

  3. Symbai commented on Mar 9, 2022

    @Symbai
    Author

    FYI: The suggested "solution" in #45143 by switching to Microsoft.Management.Infrastructure (apart from the fact that it works different and all snippets on the internet are for System.Management which makes switching difficult) is that it also doesn't work. Now the app is crashing with System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Management.Infrastructure,...

    This is because this file is also not copied to publish folder when published through VS. IF I have to copy the file myself then I can also copy wminet_utils.dll myself instead. That doesn't seem to be the right solution.

  4. ericstj commented on Mar 9, 2022

    @ericstj
    Member

    Now the app is crashing with System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Management.Infrastructure,...

    We don't support MMI here, for issues with it you may file them here https://github.com/PowerShell/MMI. It should work and many have been successful using it. Here's a sample: https://github.com/ericstj/sample-code/blob/mmi-samples/mmi-samples/Program.cs. You can also find usage in https://github.com/powershell/powershell.

    The problem is not that wminet_utils.dll is missing, it's that it's old. .NETFramework is part of the OS and we require a particular minimum version of the operating system + updates for this component to work. #29663 discusses this. I believe most versions of .NETFramework that are still in support have the required changes.

  5. Symbai commented on Mar 9, 2022

    @Symbai
    Author

    Isn't it possible to just copy the required files (the right version of wminet_utils.dll for example) to publish folder and use that one? What else is the meaning of self contained when it doesn't contain all required files? And when it's not possible, shouldn't System.Management at least get a warning somewhere that it's not fully .NET (Core) compatible because it requires .NET Framework?

  6. danmoseley commented on Mar 10, 2022

    @danmoseley
    Contributor

    What else is the meaning of self contained when it doesn't contain all required files?

    From the publishing point of view, it's not that different to user code calling into a native library - it doesn't know about it. This is even more of a corner case, as you only need a local copy if you are deploying to machine with .NET Framework older than 4.6.2. (And BTW, I am not sure we have actually tested with a local copy.)

    shouldn't System.Management at least get a warning somewhere that it's not fully .NET (Core) compatible because it requires .NET Framework?

    If there's a good place in the docs we can add the note that System.Management requires .NET Framework 4.6.2 or later.

    Note that .NET Framework, and thus wminet_utils.dll, is part of the OS on all "regular" Windows SKU's. Instead of thinking of this as ".NET Core still depends on .NET Framework" it may be better to think of this as "this legacy .NET feature requires a particular version of a Windows component"

  7. Symbai commented on Mar 10, 2022

    @Symbai
    Author

    From the publishing point of view, it's not that different to user code calling into a native library - it doesn't know about it

    On publishing a WPF application it does copy native files WPF requires to the output folder. Why can it do that on WPF but not when System.Management (or MMI) is referenced? Or let me rephrase that: If it's able to do that on WPF, can we do the same on System.Management (or MMI)? Both (all three) are not third party but products of Microsoft. And developers referencing System.Management may not know that it relies on .NET Framework (or a Windows component), just like me. They might reference and deploy it as self contained assuming it "just works" and wonder why their customers report it just crashes.

  8. removed
    untriaged
    on Mar 15, 2022
  9. added this to the Future milestone on Jul 19, 2022
  10. stepagrus commented on Mar 15, 2023

    @stepagrus

    I solved this question for myself by switching to the WMILight library instead of System.Management

  11. haseakash commented on Nov 22, 2024

    @haseakash

    I solved this question for myself by switching to the WMILight library instead of System.Management

    It works now. Just change all code with WmiLight

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions