Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Powershell 6.2.4 complains Could not load file or assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. #12004

Closed
arunswarnam opened this issue Mar 4, 2020 · 6 comments
Labels
Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a Resolution-Answered The question is answered.

Comments

@arunswarnam
Copy link

arunswarnam commented Mar 4, 2020

I am trying to run a cmdlet that is targetted for netcoreapp3.1 and I get the following error:
" Could not load file or assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified."

Looking at suggestions posted on similar threads I changed the cmdlet target framework to netStandard2.0 and I still face the same issues.

Any suggestions on how to resolve this?

Steps to reproduce

Expected behavior


Actual behavior


Environment data

.NET Core SDK (reflecting any global.json):
Version: 3.1.101
Commit: b377529961

Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.101\

Host (useful for support):
Version: 3.1.2
Commit: 916b5cba26

.NET Core SDKs installed:
3.1.101 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Name Value


PSVersion 6.2.4
PSEdition Core
GitCommitId 6.2.4
OS Microsoft Windows 10.0.18362
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0


@arunswarnam arunswarnam added the Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a label Mar 4, 2020
@iSazonov
Copy link
Collaborator

iSazonov commented Mar 4, 2020

I am trying to run a cmdlet that is targetted for netcoreapp3.1

PSVersion 6.2.4

PowerShell 6 is based on .Net Core 2.

@iSazonov iSazonov added the Resolution-Answered The question is answered. label Mar 4, 2020
@rjmholt
Copy link
Collaborator

rjmholt commented Mar 4, 2020

This is a classic framework targeting error. Some fixes for 6.2.4:

  • Retarget the project to netcoreapp2.1 and rebuild it (making sure you import the new DLL and not the old one)
  • Retarget to netstandard2.0 and rebuild it

The first will allow you to target PS 6 and 7, the second will allow you to target PS 5.1 and up, but is harder to get right, since you can only support .NET 4.6.1 and up with .NET Standard and will need to include netstandard.dll (from the NETStandard.Library NuGet package) in your module and structure it to load the right binaries on the right platforms

@arunswarnam
Copy link
Author

Got it. Taking the first approach will help my cmdlet to be used on Powershell 6 and UP right? ! Follow up question : what do I do if I have some dependencies that targets netcoreapp3.1? Is there a way to go about this without changing the dependency target?

@rjmholt
Copy link
Collaborator

rjmholt commented Mar 4, 2020

what do I do if I have some dependencies that targets netcoreapp3.1?

A netcoreapp3.1 dependency can only be used by a netcoreapp3.1 (and above) project.

To make it work, your options are:

  • If the dependencies are your own projects, migrate those projects to netcoreapp2.1 or netstandard2.0
  • If you're trying to dual target, you can target multiple TargetFrameworks (netcoreapp2.1 and netcoreapp3.1) and use the netcoreapp3.1 dependencies for one target and another dependency for another
  • If there are no substitute dependencies, I'm afraid you're out of luck. Typically though, NuGet libraries are pretty good about being written for netstandard2.0

@rjmholt
Copy link
Collaborator

rjmholt commented Mar 4, 2020

Taking the first approach will help my cmdlet to be used on Powershell 6 and UP right?

Yes, that's right

@arunswarnam
Copy link
Author

Thanks for the suggestions @rjmholt!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Question ideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a Resolution-Answered The question is answered.
Projects
None yet
Development

No branches or pull requests

3 participants