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.

Could not load file or assembly error when loading a class library from a module in beta.3

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
daxian-dbwcommented, Jul 6, 2017

Verified that the repro works with the latest powershell:

PS:68> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.0.0-beta
PSEdition                      Core
GitCommitId                    v6.0.0-beta.3-30-gece27ff68798f508c755ccb84be5ae78b386ac82
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


[F:\tmp\repro\cannotloadassembly\psmodule]
PS:69> Import-Module F:\tmp\repro\cannotloadassembly\psmodule\bin\Debug\netcoreapp2.0\psmodule.dll
[F:\tmp\repro\cannotloadassembly\psmodule]
PS:70> Get-HelloWorld
Hello World from classlibrary!

The beta.4 powershell will be released on 7/13.

2reactions
MaximoTrinidadcommented, Jul 6, 2017

Hum! I’m having a similar issue as in Beta.2 can load the Microsoft.SqlServer.Smo assembly but not in Beta.3. And, is giving a similar error message stating the assembly is not found or not loaded.

Just wondering it is related!

😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Visual Studio 2019 Error - Could not load file or assembly ...
Restart Visual Studio, clean and build a solution · Remove the class library references and add it again · Tools > Import and...
Read more >
Could not load file or assembly class library " ...
When I run the application, I receive the error: Could not load file or assembly class library "Microsoft.EntityFrameworkCore version = 6.0 ...
Read more >
Could Not Load File Or Assembly 'System.Runtime, ...
Right-click on the project and select Properties. · In the Properties window, select the Application tab. · In the Target Framework dropdown, ...
Read more >
Build error: could not load file or assembly
In this project, it looks like a (non-native) .dll is not found/included in the build. The dll is referenced in other dlls, which...
Read more >
How do I reference a .NET standard 2.0 NuGet package ...
The system cannot find the file specified.' Inner Exception: FileNotFoundException: Could not load file or assembly 'netstandard, Version=2.0.
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