8000 Could not load file or assembly error when loading a class library from a module in beta.3 · Issue #4192 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content
Could not load file or assembly error when loading a class library from a module in beta.3 #4192
@barcexwiki

Description

@barcexwiki

I have a C# Powershell module compiled with netcoreapp2.0 that uses a C# class also library compiled with netcoreapp2.0.

Since beta.3 when trying to load the class library from the module I am seeing a 'Could not load file or assembly' error. The same code works just fine in beta.2.

I have created an example case in the following repo with an example of the issue: https://github.com/barcexwiki/cannotloadassembly

In the repo, project 'psmodule' is a module that has a single cmdlet: Get-HelloWorld. This cmdlet calls an static method in a class in the 'classlibrary' project and outputs "Hello World from classlibrary!".

Steps to reproduce

D:\>git clone https://github.com/barcexwiki/cannotloadassembly.git
Cloning into 'cannotloadassembly'...
remote: Counting objects: 8, done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 8 (delta 0), reused 8 (delta 0), pack-reused 0
Unpacking objects: 100% (8/8), done.
Checking connectivity... done.

D:\>cd cannotloadassembly\psmodule

D:\cannotloadassembly\psmodule>dotnet restore
  Restoring packages for D:\cannotloadassembly\classlibrary\classlibrary.csproj...
  Restoring packages for D:\cannotloadassembly\psmodule\psmodule.csproj...
  Generating MSBuild file D:\cannotloadassembly\classlibrary\obj\classlibrary.csproj.nuget.g.props.
  Generating MSBuild file D:\cannotloadassembly\classlibrary\obj\classlibrary.csproj.nuget.g.targets.
  Restore completed in 296,18 ms for D:\cannotloadassembly\classlibrary\classlibrary.csproj.
  Generating MSBuild file D:\cannotloadassembly\psmodule\obj\psmodule.csproj.nuget.g.props.
  Generating MSBuild file D:\cannotloadassembly\psmodule\obj\psmodule.csproj.nuget.g.targets.
  Restore completed in 2,46 sec for D:\cannotloadassembly\psmodule\psmodule.csproj.

D:\cannotloadassembly\psmodule>dotnet build
Microsoft (R) Build Engine version 15.3.388.41745 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  classlibrary -> D:\cannotloadassembly\classlibrary\bin\Debug\netcoreapp2.0\classlibrary.dll
  psmodule -> D:\cannotloadassembly\psmodule\bin\Debug\netcoreapp2.0\psmodule.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:07.78


Expected behavior

Loading the module with beta.2 it loads the class library and the Get-HelloWorld cmdlet works.

D:\cannotloadassembly\psmodule>"c:\Program Files\PowerShell\6.0.0-beta.2\powershell.exe"
PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

PS D:\cannotloadassembly\psmodule> Import-Module D:\cannotloadassembly\psmodule\bin\Debug\netcoreapp2.0\psmodule.dll
PS D:\cannotloadassembly\psmodule> Get-HelloWorld
Hello World from classlibrary!

Actual behavior

Loading the module with beta.3 it loads the class library and the Get-HelloWorld cmdlet fails to load the class library.

D:\cannotloadassembly\psmodule>"c:\Program Files\PowerShell\6.0.0-beta.3\powershell.exe"
PowerShell v6.0.0-beta.3
Copyright (C) Microsoft Corporation. All rights reserved.

PS D:\cannotloadassembly\psmodule> Import-Module D:\cannotloadassembly\psmodule\bin\Debug\netcoreapp2.0\psmodule.dll
PS D:\cannotloadassembly\psmodule> Get-HelloWorld
Get-HelloWorld : Could not load file or assembly 'classlibrary, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null'. El sistema no puede encontrar el archivo especificado.
At line:1 char:1
+ Get-HelloWorld
+ ~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-HelloWorld], FileNotFoundException
    + FullyQualifiedErrorId : System.IO.FileNotFoundException,psmodule.GetHelloWorld

Environment data

for Powershell beta.2

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.0.0-beta
PSEdition                      Core
BuildVersion                   3.0.0.0
CLRVersion
GitCommitId                    v6.0.0-beta.2
OS                             Microsoft Windows 10.0.15063
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

for Powershell beta.3

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.0.0-beta
PSEdition                      Core
GitCommitId                    v6.0.0-beta.3
OS                             Microsoft Windows 10.0.15063
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

net version

> dotnet --version
2.0.0-preview2-006497

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-AnsweredThe question is answered.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0