Standard: Referencing a .net standard class library project in .net Framework web app and System.IO.FileNotFoundException throws

Created on 30 Jun 2017  路  18Comments  路  Source: dotnet/standard

Created a .net Standard 1.4 class library, and then used it in a web application created by targetting .netframework 4.6.2. when running web application the blow exception was thrown.

Could not load file or assembly 'System.Security.Claims, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

I tested same library with .net core web application and there was no error.
in .netframework web application manually installed system.security.claims 4.3 nuget package solved the problem.

I can't understand if this error is for Visual Studio 2017 tooling or Nuget package manager's package restore. but I think it should be solved.

Most helpful comment

Just so all the information is on this thread the workaround is:

For anyone that might still be hitting this you can workaround it by explicitly making the .NET Framework project a ProjectReference based project by setting the following property in the project:

<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
There is also a good change you will need auto-bindingredirects as well so make sure that is set in your project:

<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

I'm going to close this issue and if there are further questions/issue please take the conversation to dotnet/sdk#901.

All 18 comments

I had the same problem with a simple net framework console application that references a netstandard library and as workaround I had to install packages in the console application.

This is an important issue to fix because the problem manifest only at runtime so I should have to manually add all of the netstandard libraries references.

Attached a repro, just try to execute the console app that recall a function built on the netstandard library using System.IO.File, it will result in the follow

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.IO.FileSystem, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
   at ClassLibrary1.Class1.Fn()
   at ConsoleApp1.Program.Main(String[] args) in C:\Users\loren\Documents\tmp\TestNetCoreLib\ConsoleApp1\ConsoleApp1\Program.cs:line 14

ConsoleApp1.zip

Not completely sure about this, but do you have the NetStandard.Library NuGet installed?

Yes, I it was included automatically when I created the ".NET Standard 1.4" class library

csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard1.4</TargetFramework>
  </PropertyGroup>

</Project>

here more info about the environment I used:

vs

Microsoft Visual Studio Community 2017 Preview
Version 15.3.0 Preview 3.0
VisualStudio.15.Preview/15.3.0-pre.3.0+26621.2
Microsoft .NET Framework
Version 4.7.02046
Visual Basic 2017
Visual C# 2017
Visual C++ 2017
Application Insights Tools for Visual Studio Package   8.8.00613.1
ASP.NET and Web Tools 2017   15.0.30620.0
ASP.NET Core Razor Language Services   1.0
ASP.NET Template Engine 2017   15.0.30620.0
ASP.NET Web Frameworks and Tools 2017   5.2.50601.0
Azure App Service Tools v3.0.0   15.0.30615.0
Common Azure Tools   1.10
JavaScript Language Service   2.0
JavaScript Project System   2.0
JavaScript UWP Project System   2.0
Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.50612.1
Microsoft Continuous Delivery Tools for Visual Studio   0.3
Microsoft JVM Debugger   1.0
Microsoft MI-Based Debugger   1.0
Microsoft Visual C++ Wizards   1.0
Microsoft Visual Studio VC Package   1.0
NuGet Package Manager   4.3.0
SQL Server Data Tools   15.1.61702.140
TypeScript   2.3.4.0
Visual Studio Code Debug Adapter Host Package   1.0
Visual Studio tools for CMake   1.0
Visual Studio Tools for Universal indows Apps   15.0.26621.02

msbuild

Microsoft (R) Build Engine version 15.3.388.41745 for .NET Framework

I encountered this too, using vs 2017 15.3 preview 7, dependencies (nuget packages) of netstandard libraries are not copied/resolved on .netFramework projects, and you only get a runtime error.

@weshaggard

It sounds like you guys are hitting this issue https://github.com/dotnet/sdk/issues/901. Can you try the workarounds listed there and see if that helps?

@valeriob @devel0 @mesuttalebi are you unblocked here?

BTW if you haven't already you'll want to upgrade to released .NET Core 2.0 / VS 15.3

I am running into this as well. I haven't been able to solve this. I might be missing something but I did not see any workarounds in dotnet/sdk#901

I'm already on VS15.3 en Core/Standard 2.0, but it still doesn't work

I'm hitting this issue as well. Will create a repro tonight.

I have the same issue using VS 15.3 (release)
A classic project refers to netstandard2.0 class library. The packages referred from the netstandard2.0 class library doesn't follow to the classic project and then it crashes at runtime.

@ericstj @weshaggard can you please help troubleshoot this one...

As I reported on dotnet/sdk#901 I was able to get this to correctly work by putting <RestoreProjectStyle>PackageReference</RestoreProjectStyle> in the .NET Framework csproj. @cann @stebet can you please try that with your project?

Just so all the information is on this thread the workaround is:

For anyone that might still be hitting this you can workaround it by explicitly making the .NET Framework project a ProjectReference based project by setting the following property in the project:

<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
There is also a good change you will need auto-bindingredirects as well so make sure that is set in your project:

<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

I'm going to close this issue and if there are further questions/issue please take the conversation to dotnet/sdk#901.

@weshaggard TYVM for the workaround. Worked a treat. Although now I have a million new compiler warnings since my Stylecop analysers in the .NET Standard project are now being included in my .NET 4.6.1 unit tests :/

2018.07.02 same problom vs2017 15.7.3

@weshaggard I am using asp.net website project(webform), and there is no csproj file to edit.
Is it possible make it work?

Find solution here,

In web sites, you cannot use PackageReference as there is no project file. In that case, you need to install all NuGet packages into your web site that any of the direct or indirect project references depend on.

Was this page helpful?
0 / 5 - 0 ratings