Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

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

Closed
mesuttalebi opened this issue Jun 30, 2017 · 18 comments

Comments

@mesuttalebi
Copy link

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.

@devel0
Copy link

devel0 commented Jul 7, 2017

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

@myokeeh
Copy link

myokeeh commented Jul 7, 2017

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

@devel0
Copy link

devel0 commented Jul 9, 2017

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

@valeriob
Copy link

valeriob commented Aug 4, 2017

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.

@Petermarcu
Copy link
Member

@weshaggard

@weshaggard
Copy link
Member

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

@danmoseley
Copy link
Member

@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

@remcolam
Copy link

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

@stebet
Copy link

stebet commented Aug 16, 2017

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

@cannn
Copy link

cannn commented Aug 17, 2017

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.

@danmoseley
Copy link
Member

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

@weshaggard
Copy link
Member

weshaggard commented Aug 17, 2017

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?

@weshaggard
Copy link
Member

weshaggard commented Aug 17, 2017

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.

@ne1410s
Copy link

ne1410s commented Feb 17, 2018

@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 :/

@GF-Huang
Copy link

GF-Huang commented Jul 2, 2018

2018.07.02 same problom vs2017 15.7.3

@chucklu
Copy link

chucklu commented Jul 26, 2018

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

@chucklu
Copy link

chucklu commented Jul 26, 2018

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests