question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Microsoft.Management.Infrastructure can't be loaded in latest .NET 8 Preview 5 build

See original GitHub issue

Prerequisites

Steps to reproduce

This is a regression between build 8.0.100-preview.5.23267.7 and 8.0.100-preview.5.23269.4. It was discovered when attempting to update the .NET Docker images to the latest build of Preview 5. You can see the CI results with this error here: https://github.com/dotnet/dotnet-docker/pull/4628

This affects Windows only.

Build this Dockerfile:

# escape=`

FROM mcr.microsoft.com/windows/servercore:ltsc2022 AS installer

RUN powershell -Command " `
        $ErrorActionPreference = 'Stop'; `
        $ProgressPreference = 'SilentlyContinue'; `
        `
        # Retrieve .NET SDK
        $sdk_version = '8.0.100-preview.5.23269.4'; `
        Invoke-WebRequest -OutFile dotnet.zip https://dotnetbuilds.azureedge.net/public/Sdk/$sdk_version/dotnet-sdk-$sdk_version-win-x64.zip; `
        mkdir $Env:ProgramFiles\dotnet; `
        tar -oxzf dotnet.zip -C $Env:ProgramFiles\dotnet; `
        Remove-Item -Force dotnet.zip;"

RUN powershell -Command " `
        $ErrorActionPreference = 'Stop'; `
        $ProgressPreference = 'SilentlyContinue'; `
        `
        # Install PowerShell global tool
        $powershell_version = '7.4.0-preview.3'; `
        Invoke-WebRequest -OutFile PowerShell.Windows.x64.$powershell_version.nupkg https://pwshtool.blob.core.windows.net/tool/$powershell_version/PowerShell.Windows.x64.$powershell_version.nupkg; `
        & $Env:ProgramFiles\dotnet\dotnet tool install --add-source . --tool-path $Env:ProgramFiles\powershell --version $powershell_version PowerShell.Windows.x64; `
        & $Env:ProgramFiles\dotnet\dotnet nuget locals all --clear; `
        Remove-Item -Force PowerShell.Windows.x64.$powershell_version.nupkg; `
        Remove-Item -Path $Env:ProgramFiles\powershell\.store\powershell.windows.x64\$powershell_version\powershell.windows.x64\$powershell_version\powershell.windows.x64.$powershell_version.nupkg -Force;"

RUN setx /M PATH "%PATH%;C:\Program Files\powershell;C:\Program Files\dotnet"

RUN pwsh --version

Expected behavior

It should be able to run `pwsh` without failure.

Actual behavior

Process terminated. The type initializer for 'System.Management.Automation.PSVersionInfo' threw an exception.
   at System.Environment.FailFast(System.String, System.Exception)
   at Microsoft.PowerShell.UnmanagedPSEntry.Start(System.String[], Int32)
   at Microsoft.PowerShell.ManagedPSEntry.Main(System.String[])
System.TypeInitializationException: The type initializer for 'System.Management.Automation.PSVersionInfo' threw an exception.
 ---> System.TypeInitializationException: The type initializer for 'System.Management.Automation.PSObject' threw an exception.
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
File name: 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
   at System.Management.Automation.PSObject..cctor()
   --- End of inner exception stack trace ---
   at System.Management.Automation.PSObject.get_Properties()
   at System.Management.Automation.SemanticVersion.op_Implicit(SemanticVersion semver)
   at System.Management.Automation.PSVersionInfo..cctor()
   --- End of inner exception stack trace ---
   at System.Management.Automation.PSVersionInfo.get_PSVersion()
   at System.Management.Automation.PSSnapInReader.ReadRegistryInfo(Version& assemblyVersion, String& publicKeyToken, String& culture, String& applicationBase, Version& psVersion)
   at System.Management.Automation.PSSnapInReader.ReadCoreEngineSnapIn()
   at System.Management.Automation.Runspaces.InitialSessionState.ImportCorePSSnapIn()
   at System.Management.Automation.Runspaces.InitialSessionState.CreateDefault2()
   at Microsoft.PowerShell.UnmanagedPSEntry.Start(String[] args, Int32 argc)The command 'cmd /S /C pwsh --version' returned a non-zero code: 2148734499


### Error details

_No response_

### Environment data

```powershell
Can't run it because pwsh fails to run.

Visuals

No response

Issue Analytics

  • State:closed
  • Created 4 months ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
daxian-dbwcommented, Jul 17, 2023

@AnatoliB Just FYI, it’s also blocking our adoption of the .NET 8 preivew.5 and preview.6.

1reaction
Francisco-Gaminocommented, Jul 11, 2023

Hello @daxian-dbw and @adityapatwardhan – We need this fix for Azure Functions. Please keep us in the loop.

/cc @anatolib @paulyuk @shreyabatra4

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Could not load file or assembly 'Microsoft.Management ...
I am writing a multi-platform c# command line application using .NET Core 3.1 that will need to work as a single executable. I...
Read more >
Announcing .NET 8 Preview 5
We're excited to share all the new features and improvements in .NET 8 Preview 5! This release is a follow-up to the Preview...
Read more >
Troubleshoot .NET Framework targeting errors
To resolve the error, make sure that your application targets a .NET version that's compatible with the version that's targeted by the projects ......
Read more >
ASP.NET Core updates in .NET 8 Preview 1
NET 8 Preview 1 is now available! Check out what's new in ASP.NET Core in this update and learn about the roadmap for...
Read more >
MSB3277: Found conflicts between different versions of ' ...
This error occurs during a build when more than one version of the same dependent assembly is referenced in a build of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found