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

.NET Framework app fails with "Could not load file or assembly 'netstandard, Version=2.0.0.0'" #328

Closed
natemcmaster opened this Issue May 5, 2017 · 28 comments

Comments

Projects
None yet
@natemcmaster
Member

natemcmaster commented May 5, 2017

Executing a .NET Framework 4.6.1 console app that references a .NET Standard 2.0 assembly fails with

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
   at TestApp.Program.Main(String[] args)

Repro

Create a .NET Framework 4.6.1 app that references a .NET Standard 2.0 library.

Example: TestApp --> TestLib

TestLib

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
</Project>
using System.Runtime.InteropServices;

namespace TestLib
{
    public class Class1
    {
        public static string FrameworkDescription => RuntimeInformation.FrameworkDescription;
    }
}

TestApp

<Project Sdk="Microsoft.NET.Sdk">
  <ItemGroup>
    <ProjectReference Include="..\TestLib\TestLib.csproj" />
  </ItemGroup>
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net461</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="NETStandard.Library" Version="$(BundledNETStandardPackageVersion)" />
  </ItemGroup>
</Project>
using System;
using TestLib;

namespace TestApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Class1.FrameworkDescription);
        }
    }
}

Details

dotnet/cli: 2.0.0-preview2-005905
NETStandard.Library package version: 2.0.0-preview2-25226-01

@dasMulli

This comment has been minimized.

Show comment
Hide comment
@dasMulli
Contributor

dasMulli commented May 5, 2017

@weshaggard

This comment has been minimized.

Show comment
Hide comment
@weshaggard

weshaggard May 5, 2017

Member

You need to add a reference to NETStandard.Library.NETFramework package to get this dependency now.

Member

weshaggard commented May 5, 2017

You need to add a reference to NETStandard.Library.NETFramework package to get this dependency now.

@natemcmaster

This comment has been minimized.

Show comment
Hide comment
@natemcmaster

natemcmaster May 5, 2017

Member

Thanks, that fixes it. I never would have figured that out from error messages or tooling alone. I'm assuming this is just a pre-release rough edge. Are there plans to make the reference automatic or to make this more obvious to end users?

Member

natemcmaster commented May 5, 2017

Thanks, that fixes it. I never would have figured that out from error messages or tooling alone. I'm assuming this is just a pre-release rough edge. Are there plans to make the reference automatic or to make this more obvious to end users?

@weshaggard

This comment has been minimized.

Show comment
Hide comment
@weshaggard

weshaggard May 5, 2017

Member

Correct that is the sdk bug that was linked above.

Member

weshaggard commented May 5, 2017

Correct that is the sdk bug that was linked above.

@natemcmaster

This comment has been minimized.

Show comment
Hide comment
@natemcmaster

natemcmaster May 5, 2017

Member

Ok, thanks.

Member

natemcmaster commented May 5, 2017

Ok, thanks.

@amasoumi

This comment has been minimized.

Show comment
Hide comment
@amasoumi

amasoumi Sep 5, 2017

Hi Guys,
I am having exact same issue, but in my case I am creating a extension package, I tried all the workaround suggested, but had no luck, I added NETStandard.Library.NETFramework as well on the extension package but still having same exact problem, any thoughts would be appreciated!
thanks

System.IO.FileNotFoundException: 'Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.'

amasoumi commented Sep 5, 2017

Hi Guys,
I am having exact same issue, but in my case I am creating a extension package, I tried all the workaround suggested, but had no luck, I added NETStandard.Library.NETFramework as well on the extension package but still having same exact problem, any thoughts would be appreciated!
thanks

System.IO.FileNotFoundException: 'Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.'

@rkeithhill

This comment has been minimized.

Show comment
Hide comment
@rkeithhill

rkeithhill Sep 22, 2017

I think the NETStandard.Library has to be added to the .NET Framework app. In my case, the ..NET Framework app is a shipping version of PowerShell 5.1. I'm trying to build netstandard2.0 based PowerShell module i.e. extension. The module loads but fails when I execute my custom command with the same error.

rkeithhill commented Sep 22, 2017

I think the NETStandard.Library has to be added to the .NET Framework app. In my case, the ..NET Framework app is a shipping version of PowerShell 5.1. I'm trying to build netstandard2.0 based PowerShell module i.e. extension. The module loads but fails when I execute my custom command with the same error.

@MihaMarkic

This comment has been minimized.

Show comment
Hide comment
@MihaMarkic

MihaMarkic Oct 11, 2017

Not sure whether to create a new issue, I'll post it here because it seems to fit.
The code below is run from a .net 4.6.2 console and ClassLibrary2.dll is a .net standard 2.0 library.
GetExportedTypes() method would throw

System.IO.FileNotFoundException: 'Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.'

unless I add the deprecated NETStandard.Library.NETFramework to the console.

Repro code

const string file = @"[PATH]\ClassLibrary2.dll";
var assembly = Assembly.LoadFile(file);
var types = assembly.GetExportedTypes();

MihaMarkic commented Oct 11, 2017

Not sure whether to create a new issue, I'll post it here because it seems to fit.
The code below is run from a .net 4.6.2 console and ClassLibrary2.dll is a .net standard 2.0 library.
GetExportedTypes() method would throw

System.IO.FileNotFoundException: 'Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.'

unless I add the deprecated NETStandard.Library.NETFramework to the console.

Repro code

const string file = @"[PATH]\ClassLibrary2.dll";
var assembly = Assembly.LoadFile(file);
var types = assembly.GetExportedTypes();
@kwaazaar

This comment has been minimized.

Show comment
Hide comment
@kwaazaar

kwaazaar Oct 11, 2017

Where can I find NETStandard.Library.NETFramework? Nuget only finds NETStandard.Library.

kwaazaar commented Oct 11, 2017

Where can I find NETStandard.Library.NETFramework? Nuget only finds NETStandard.Library.

@MihaMarkic

This comment has been minimized.

Show comment
Hide comment
@MihaMarkic

MihaMarkic Oct 11, 2017

@kwaazaar
It's NETStandard.Library.NETFramework and make sure you tick "Include prerelease" checkbox.

MihaMarkic commented Oct 11, 2017

@kwaazaar
It's NETStandard.Library.NETFramework and make sure you tick "Include prerelease" checkbox.

@dasMulli

This comment has been minimized.

Show comment
Hide comment
@dasMulli

dasMulli Oct 11, 2017

Contributor

It should no longer be necessary to use the NETStandard.Library.NETFramework, it was a temporary method. The tooling is now included in VS (with some issues - see
dotnet/announcements#31)

If you load an app via reflection and not during the build process, you should be able to force the build process to run the necessary logic by putting this into a PropertyGroup in your consuming application:

<DependsOnNETStandard>true</DependsOnNETStandard>

If you run on 4.7.1, it should work out of the box (haven't tried though)

Contributor

dasMulli commented Oct 11, 2017

It should no longer be necessary to use the NETStandard.Library.NETFramework, it was a temporary method. The tooling is now included in VS (with some issues - see
dotnet/announcements#31)

If you load an app via reflection and not during the build process, you should be able to force the build process to run the necessary logic by putting this into a PropertyGroup in your consuming application:

<DependsOnNETStandard>true</DependsOnNETStandard>

If you run on 4.7.1, it should work out of the box (haven't tried though)

@xzuttz

This comment has been minimized.

Show comment
Hide comment
@xzuttz

xzuttz Oct 14, 2017

Added NETStandard.Library.NETFramework to a 4.6.2 Console application, which references a .NET Standard 2.0 library. Also added

<DependsOnNETStandard>true</DependsOnNETStandard>

to a PropertyGroup in the console application.

Recieving the following error:

System.IO.FileNotFoundException: 'Could not load file or assembly 'Titanium.Web.Proxy.Standard, Version=3.0.130.0, Culture=neutral, PublicKeyToken=8e41e1f1c790d7cf' or one of its dependencies. The system cannot find the file specified.'

xzuttz commented Oct 14, 2017

Added NETStandard.Library.NETFramework to a 4.6.2 Console application, which references a .NET Standard 2.0 library. Also added

<DependsOnNETStandard>true</DependsOnNETStandard>

to a PropertyGroup in the console application.

Recieving the following error:

System.IO.FileNotFoundException: 'Could not load file or assembly 'Titanium.Web.Proxy.Standard, Version=3.0.130.0, Culture=neutral, PublicKeyToken=8e41e1f1c790d7cf' or one of its dependencies. The system cannot find the file specified.'

@MihaMarkic

This comment has been minimized.

Show comment
Hide comment
@MihaMarkic

MihaMarkic Oct 15, 2017

@dasMulli Indeed it works that way. Didn't try 4.7.1.

MihaMarkic commented Oct 15, 2017

@dasMulli Indeed it works that way. Didn't try 4.7.1.

@schungx

This comment has been minimized.

Show comment
Hide comment
@schungx

schungx Mar 10, 2018

In my case, one of my DLL's consistently gives this error and refuses to load (while all others load fine).

The root of my main program is .NET Core APP, while all the DLL's are .NET Standard 2.0.

Turns out that I need to reference NetStandard.Library in the main .NET Core APP to get the error to go away. No idea why all other DLL's don't require it though...

Anyway:

    <PackageReference Include="NETStandard.Library" Version="2.0.1" />

does the magic.

schungx commented Mar 10, 2018

In my case, one of my DLL's consistently gives this error and refuses to load (while all others load fine).

The root of my main program is .NET Core APP, while all the DLL's are .NET Standard 2.0.

Turns out that I need to reference NetStandard.Library in the main .NET Core APP to get the error to go away. No idea why all other DLL's don't require it though...

Anyway:

    <PackageReference Include="NETStandard.Library" Version="2.0.1" />

does the magic.

@abatishchev

This comment has been minimized.

Show comment
Hide comment
@abatishchev

abatishchev May 31, 2018

If I'm targeting net462 i'm getting netstandard in my output (Service Fabric application) but if net472 then I'm not (because it's GAC'd as part of the SDK installation) so it's not getting packaged thus not deployed to the cluster, and the app doesn't work. Thoughts?

abatishchev commented May 31, 2018

If I'm targeting net462 i'm getting netstandard in my output (Service Fabric application) but if net472 then I'm not (because it's GAC'd as part of the SDK installation) so it's not getting packaged thus not deployed to the cluster, and the app doesn't work. Thoughts?

@mbatista

This comment has been minimized.

Show comment
Hide comment
@mbatista

mbatista Jul 13, 2018

@weshaggard @karelz

What is the current solution for this now that the https://www.nuget.org/packages/NETStandard.Library.NETFramework/ is deprecated?

Using VS2015, .Net461,
I need to reference netstandard2 in my project to use some abstractions from another package. When I try to deploy my cloud service to azure I get a "Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies"

thanks in advance

mbatista commented Jul 13, 2018

@weshaggard @karelz

What is the current solution for this now that the https://www.nuget.org/packages/NETStandard.Library.NETFramework/ is deprecated?

Using VS2015, .Net461,
I need to reference netstandard2 in my project to use some abstractions from another package. When I try to deploy my cloud service to azure I get a "Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies"

thanks in advance

@weshaggard

This comment has been minimized.

Show comment
Hide comment
@weshaggard

weshaggard Jul 13, 2018

Member

I don't believe it is supported in VS2015. If you have the newer VS2017 tooling it will copy this binary into your output automatically as part of the build.

Member

weshaggard commented Jul 13, 2018

I don't believe it is supported in VS2015. If you have the newer VS2017 tooling it will copy this binary into your output automatically as part of the build.

@abatishchev

This comment has been minimized.

Show comment
Hide comment
@abatishchev

abatishchev Jul 13, 2018

It will if targets net462, it won't if targets net472

abatishchev commented Jul 13, 2018

It will if targets net462, it won't if targets net472

@eluchsinger

This comment has been minimized.

Show comment
Hide comment
@eluchsinger

eluchsinger Aug 22, 2018

How is it possible that this bug still exists? And no official solution?!

eluchsinger commented Aug 22, 2018

How is it possible that this bug still exists? And no official solution?!

@karelz

This comment has been minimized.

Show comment
Hide comment
@karelz

karelz Aug 22, 2018

Member

@eluchsinger this bug was closed more than a year ago: #328 (comment) (so was the other one linked above: dotnet/sdk#992 (comment))

Either you're using old bits, or there is a new/different bug with similar symptoms, or the original bug was not properly addressed. Either way, I'd recommend to try latest bits which are supposed to be fixed (from the linked SDK bug). If it still fails, please provide detailed information about what fails for you under which conditions, etc. -- ideally minimal repro -- in a new bug. Thanks!

Member

karelz commented Aug 22, 2018

@eluchsinger this bug was closed more than a year ago: #328 (comment) (so was the other one linked above: dotnet/sdk#992 (comment))

Either you're using old bits, or there is a new/different bug with similar symptoms, or the original bug was not properly addressed. Either way, I'd recommend to try latest bits which are supposed to be fixed (from the linked SDK bug). If it still fails, please provide detailed information about what fails for you under which conditions, etc. -- ideally minimal repro -- in a new bug. Thanks!

@abatishchev

This comment has been minimized.

Show comment
Hide comment
@abatishchev

abatishchev Aug 22, 2018

Was it fixed? If yes then wheere and how? And what should be done to dtart using it? There are so many discussions that went nowhere so it's hard to tell what was the final outcome.

abatishchev commented Aug 22, 2018

Was it fixed? If yes then wheere and how? And what should be done to dtart using it? There are so many discussions that went nowhere so it's hard to tell what was the final outcome.

@eluchsinger

This comment has been minimized.

Show comment
Hide comment
@eluchsinger

eluchsinger Aug 22, 2018

@karelz it's really hard to provide a repro when the source for the error is hidden somewhere in the configs of our solution and the error message is not helpful.

I see that in the second link you posted (dotnet/sdk#992 (comment)) there are unanswered questions in the end.

I am using Visual Studio 15.8.1. I am targeting net472 and I get that error. I have also added NETStandardLibrary (latest) as a Nuget, but it didn't help. I will spend more time debugging tomorrow.

eluchsinger commented Aug 22, 2018

@karelz it's really hard to provide a repro when the source for the error is hidden somewhere in the configs of our solution and the error message is not helpful.

I see that in the second link you posted (dotnet/sdk#992 (comment)) there are unanswered questions in the end.

I am using Visual Studio 15.8.1. I am targeting net472 and I get that error. I have also added NETStandardLibrary (latest) as a Nuget, but it didn't help. I will spend more time debugging tomorrow.

@karelz

This comment has been minimized.

Show comment
Hide comment
@karelz

karelz Aug 22, 2018

Member

cc @joperezr @safern @weshaggard if they have any pro tips / suggestions how to debug it (MSBuild logs?).

Member

karelz commented Aug 22, 2018

cc @joperezr @safern @weshaggard if they have any pro tips / suggestions how to debug it (MSBuild logs?).

@joperezr

This comment has been minimized.

Show comment
Hide comment
@joperezr

joperezr Aug 22, 2018

Member

It will if targets net462, it won't if targets net472

That is by design. Net472 doesn't need the support package, because the required files we need in order to run are already installed in the GAC for .NET Framework 4.7.2.
For people still hitting this, and specially if they are hitting it at build-time, then please do upload a msbuild binlog file here so that we can take a look and figure out what is going on. In order to produce a binlog simply run msbuild yourProject /t:rebuild /bl from a developer command prompt.

Member

joperezr commented Aug 22, 2018

It will if targets net462, it won't if targets net472

That is by design. Net472 doesn't need the support package, because the required files we need in order to run are already installed in the GAC for .NET Framework 4.7.2.
For people still hitting this, and specially if they are hitting it at build-time, then please do upload a msbuild binlog file here so that we can take a look and figure out what is going on. In order to produce a binlog simply run msbuild yourProject /t:rebuild /bl from a developer command prompt.

@abatishchev

This comment has been minimized.

Show comment
Hide comment
@abatishchev

abatishchev Aug 25, 2018

So I switched my project to net472, built and netstandard.dll is not in the output. So the app won't work on Service Fabric Cluster which doesn't have net472 installed yet. What's not the case for net462 which brings netstandard.dll with it.

alexbat_msbuild.zip

abatishchev commented Aug 25, 2018

So I switched my project to net472, built and netstandard.dll is not in the output. So the app won't work on Service Fabric Cluster which doesn't have net472 installed yet. What's not the case for net462 which brings netstandard.dll with it.

alexbat_msbuild.zip

@relair

This comment has been minimized.

Show comment
Hide comment
@relair

relair Aug 26, 2018

I've switched my .net core console project targeted at full framework from net471 to net461 and it does now include netstandard.dll in the output which wasn't the case before. It definitely seems like a bug, fortunately I should be fine with slightly lower framework version.

relair commented Aug 26, 2018

I've switched my .net core console project targeted at full framework from net471 to net461 and it does now include netstandard.dll in the output which wasn't the case before. It definitely seems like a bug, fortunately I should be fine with slightly lower framework version.

@Petermarcu

This comment has been minimized.

Show comment
Hide comment
@Petermarcu

Petermarcu Aug 26, 2018

Member

Right. Netstandard.dll is built into 4.7.1 so you don't need it in your app if you are guaranteed to run on 4.7.1 or higher. That's the designed behavior.

Member

Petermarcu commented Aug 26, 2018

Right. Netstandard.dll is built into 4.7.1 so you don't need it in your app if you are guaranteed to run on 4.7.1 or higher. That's the designed behavior.

@rnandikotkur

This comment has been minimized.

Show comment
Hide comment
@rnandikotkur

rnandikotkur Oct 3, 2018

Executing a .NET Framework 4.6.1 console app that references a .NET Standard 2.0 assembly fails with

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
   at TestApp.Program.Main(String[] args)

Repro

Create a .NET Framework 4.6.1 app that references a .NET Standard 2.0 library.

Example: TestApp --> TestLib

TestLib

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
</Project>
using System.Runtime.InteropServices;

namespace TestLib
{
    public class Class1
    {
        public static string FrameworkDescription => RuntimeInformation.FrameworkDescription;
    }
}

TestApp

<Project Sdk="Microsoft.NET.Sdk">
  <ItemGroup>
    <ProjectReference Include="..\TestLib\TestLib.csproj" />
  </ItemGroup>
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net461</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="NETStandard.Library" Version="$(BundledNETStandardPackageVersion)" />
  </ItemGroup>
</Project>
using System;
using TestLib;

namespace TestApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Class1.FrameworkDescription);
        }
    }
}

Details

dotnet/cli: 2.0.0-preview2-005905
NETStandard.Library package version: 2.0.0-preview2-25226-01

I ran into the same issue, found out that below entry is added to .csproj file when dependency package is added.

<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
  <HintPath>..\packages\System.Buffers.4.5.0\lib\netstandard**2.0**\System.Buffers.dll</HintPath>
</Reference>

Edit this file manually, change it as shown below. It should resolve it.

<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
  <HintPath>..\packages\System.Buffers.4.5.0\lib\netstandard**1.1**\System.Buffers.dll</HintPath>
</Reference>

rnandikotkur commented Oct 3, 2018

Executing a .NET Framework 4.6.1 console app that references a .NET Standard 2.0 assembly fails with

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
   at TestApp.Program.Main(String[] args)

Repro

Create a .NET Framework 4.6.1 app that references a .NET Standard 2.0 library.

Example: TestApp --> TestLib

TestLib

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
</Project>
using System.Runtime.InteropServices;

namespace TestLib
{
    public class Class1
    {
        public static string FrameworkDescription => RuntimeInformation.FrameworkDescription;
    }
}

TestApp

<Project Sdk="Microsoft.NET.Sdk">
  <ItemGroup>
    <ProjectReference Include="..\TestLib\TestLib.csproj" />
  </ItemGroup>
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net461</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="NETStandard.Library" Version="$(BundledNETStandardPackageVersion)" />
  </ItemGroup>
</Project>
using System;
using TestLib;

namespace TestApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Class1.FrameworkDescription);
        }
    }
}

Details

dotnet/cli: 2.0.0-preview2-005905
NETStandard.Library package version: 2.0.0-preview2-25226-01

I ran into the same issue, found out that below entry is added to .csproj file when dependency package is added.

<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
  <HintPath>..\packages\System.Buffers.4.5.0\lib\netstandard**2.0**\System.Buffers.dll</HintPath>
</Reference>

Edit this file manually, change it as shown below. It should resolve it.

<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
  <HintPath>..\packages\System.Buffers.4.5.0\lib\netstandard**1.1**\System.Buffers.dll</HintPath>
</Reference>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment