Skip to content

Could not load file or assembly 'System.Management.Automation' after update to .NET 7 #19078

Closed

Description

Prerequisites

Steps to reproduce

After updating our project to .NET 7, we are unable to run any of our tests via Windows PowerShell using NUnitConsole 3.16.x

Running the same tests with dotnet test works just fine.

Scripts are run on PowerShell 5.1.19041.1237 and Windows 10 (build 19043.1288). We did try to use the newest version of PS as well but without any success.

Removing reference to Microsoft.PowerShell.SDK from the project allows us to run tests via NUnitConsole, however we don't have any idea why is that the case.

NuGet packages in output project which may have some influence:

"Microsoft.NET.Test.Sdk" Version="17.4.1"
"Moq" Version="4.18.4"
"MSTest.TestAdapter" Version="3.0.2"
"MSTest.TestFramework" Version="3.0.2"
"NUnit3TestAdapter" Version="4.3.1"
"Microsoft.PowerShell.SDK" Version="7.3.1"

Expected behavior

Running `.\nunit3-console.exe("tests.dll")` command in PowerShell should start our tests.

Actual behavior

We get an error:

Unable to load one or more of the requested types.
Could not load file or assembly 'System.Management.Automation, Version=7.3.1.0

Environment data

Name                           Value
----                           -----
PSVersion                      5.1.19041.1237
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1237
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Activity

  1. everything411 commented on Feb 2, 2023

    @everything411

    same problem.

    PS C:\Users\everything411> Compare-Object
    Compare-Object: The 'Compare-Object' command was found in the module 'Microsoft.PowerShell.Utility', but the module could not be loaded due to the following error: [Could not load file or assembly 'System.Management.Automation, Version=7.3.2.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. 系统找不到指定的文件。]
    For more information, run 'Import-Module Microsoft.PowerShell.Utility'.
    

    everything in Microsoft.PowerShell.Utility failed to work properly

  2. iSazonov commented on Feb 2, 2023

    @iSazonov
    Collaborator

    Seems dup #16862

  3. adityapatwardhan commented on Apr 18, 2023

    @adityapatwardhan
    Member

    The issue is fixed by #19302

    Please re-open if you still see the issue.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions