PowerShell / MMI

Other
26 stars 17 forks source link

Version 3.0.0 doesn't work with .NET 8 runtime win-x64 #57

Open mk185147 opened 1 year ago

mk185147 commented 1 year ago

Prerequisites

Steps to reproduce

I build my app with .NET 8, runtime win-x64 and Microsoft.Management.Infrastructure version 3.0.0 and let it run.

I am able to get my .NET 8 app running when built with Microsoft.Management.Infrastructure version 3.0.0-preview.3, the issue is also happening with 3.0.0-preview.4.

Expected behavior

No problem

Actual behavior

When application start I get exception:

System.TypeInitializationException: The type initializer for 'Microsoft.Management.Infrastructure.Native.ApplicationMethods' threw an exception.
  ---> System.DllNotFoundException: Unable to load DLL 'Microsoft.Management.Infrastructure.Native.Unmanaged.DLL' or one of its dependencies: The specified module could not be found. (0x8007007E)
    at MI_ApplicationWrapper_Initialize(_MI_ApplicationWrapper* , UInt16* ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  ,  )
    at Microsoft.Management.Infrastructure.Native.MI_ApplicationWrapper_Initialize_Managed(_MI_ApplicationWrapper* pmiApplicationWrapper)
    at Microsoft.Management.Infrastructure.Native.ApplicationMethods.InitializeCore(InstanceHandle& errorDetails, ApplicationHandle& applicationHandle)
    at Microsoft.Management.Infrastructure.Native.ApplicationMethods..cctor()
    --- End of inner exception stack trace ---
    at Microsoft.Management.Infrastructure.Native.ApplicationMethods.Initialize(InstanceHandle& errorDetails, ApplicationHandle& applicationHandle)
    at Microsoft.Management.Infrastructure.Internal.CimApplication.GetApplicationHandle()
    at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
 --- End of stack trace from previous location ---
    at System.Lazy`1.CreateValue()
    at Microsoft.Management.Infrastructure.Internal.CimApplication.get_Handle()
    at Microsoft.Management.Infrastructure.CimSession.Create(String computerName, CimSessionOptions sessionOptions)
    at Microsoft.Management.Infrastructure.CimSession.Create(String computerName)

Error details

No response

Environment data

The application run on cotainer without powershell

Version

3.0.0

Visuals

No response

Kryptos-FR commented 12 months ago

In addition, where is the source of version 3? It's not in this repo (or I couldn't find the right branch).

ds185357 commented 9 months ago

The same issue is still present in the version v3.0.0

mk185147 commented 9 months ago

Looking into the nuget package Microsoft.Management.Infrastructure.Runtime.Win I see that the version 3.0.0 doesn't contain files runtimes*\native\mi.dll and runtimes*\native\miutils.dll which were present in the preview 3 nuget package.

mk185147 commented 6 months ago

@adityapatwardhan and @daxian-dbw can you, please, help? I saw in the ticket https://github.com/dotnet/runtime/issues/86713 that you were probably preparing a solution for use these powershell nuget packages with .NET 8 but it isn't clear to me what is the expectation. I see that mi.dll and miutils.dll aren't included in Microsoft.Management.Infrastructure.Runtime.Win anymore - is it expected? Is there other way how can I deliver these dlls to a windows container? Thanks

daxian-dbw commented 6 months ago

@mk185147 Regarding that .NET issue, the v3.0.0 of the MMI package resolves the problem -- PowerShell 7.4 and applications that host PowerShell 7.4 will continue to work without needing to make the runtimeconfig change.

I believe mi.dll and miutils.dll were removed from the v3.0.0 package because they are available under C:\Windows\System32 on Windows machines, so there is no need to include an older version of those 2 libraries in the NuGet package. But I don't know about the specifics. @adityapatwardhan made the changes and would have more insights.

mk185147 commented 6 months ago

Thank you @daxian-dbw . Unfortunately, mi.dll and miutils.dll aren't present on Windows Nano Server containers, that is where is see the System.TypeInitializationException when using Microsoft.Management.Infrastructure version 3.0.0 (and it worked with 3.0.0-preview.3 where the mi.dll and miutils.dll were present). Do you know about a good way how to deliver mi.dll and miutils.dll into Windows nano cotnainers? Thanks