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

NuGet dependencies of .NET Standard library referenced from classic .NET app cannot be resolved at runtime with FileNotFoundException #1582

Closed
OutSorcerer opened this issue Jan 18, 2017 · 8 comments
Labels

Comments

@OutSorcerer
Copy link

OutSorcerer commented Jan 18, 2017

This issue is reproduced in that repository. Just build it and run ClassicConsoleApp.

Let's assume there is a simple .NET Standard library that has a dependency from Newtonsoft.Json NuGet package. And this library, in turn, is referenced by a classic .NET 4.6.1 console application. This solution builds successfully but during runtime when console application tries to instantiate a class from .NET standard library the following exception is thrown:

System.IO.FileNotFoundException: 'Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.'

One possible workaround is to manually copy Newtonsoft.Json.dll from C:\Users\{username}\.nuget\packages\newtonsoft.json\9.0.1\lib\netstandard1.0 to the output folder of the classic .NET console application. Maybe msbuild should do it automatically.

When referencing the same library but from .NET Core console application Newtonsoft.Json.dll is also missing in output folder but the program works as expected. In this case Newtonsoft.Json dependency is included in CoreConsoleApp.deps.json that is missing in output folder for the classic .NET application.

CoreConsoleApp.runtimeconfig.dev.json file in .NET Core console app output folder with

{
  "runtimeOptions": {
    "additionalProbingPaths": [
      "C:\\Users\\{username}\\.nuget\\packages"
    ]
  }
}

could be another hint for runtime to locate Newtonsoft.Json.dll. This file is also missing in classic .NET application's output.

I am working with

Microsoft (R) Build Engine version 15.1.458.808

and

Microsoft Visual Studio Professional 2017 RC
Version 15.0.26020.0 D15REL

This problem exists at least from August 2016 and was mentioned in this and this stackoverflow questions but there are no solutions yet.

@dsplaisted
Copy link
Member

I believe this will be fixed once Visual Studio supports PackageReference instead of packages.config for .NET Framework projects: https://aka.ms/packagereferencesupport

@OutSorcerer
Copy link
Author

@dsplaisted But VS 2017 RC already supports it. At least partially because I added a PackageReference to Newtonsoft.Json in my example project from VS GUI. And I did not use packages.config.

Moreover, when I build the example solution from the command line with msbuild 15.1.458.808 it builds successfully but I get the same error at runtime so this issue is related to msbuild not only (or not at all) to VS .NET Core tooling.

@OutSorcerer OutSorcerer changed the title Nuget dependencies of .NET Standard Library referenced from classic .NET app cannot be resolved at runtime with FileNotFoundException NuGet dependencies of .NET Standard library referenced from classic .NET app cannot be resolved at runtime with FileNotFoundException Jan 19, 2017
@OutSorcerer
Copy link
Author

Found another workaround by creating NuGet package out of .NET Standard library.
I hope @dsplaisted is right and PackageReference will work in best case after the next update of VS 2017 RC.
However, it would be nice to have a link to related GitHub commits/issues/etc. if someone would provide such information.

@OutSorcerer
Copy link
Author

OutSorcerer commented Jan 31, 2017

@dsplaisted Unfortunately, the recent update of VS 2017 RC didn't fix this issue.

The repository with a repro is updated according to new csproj format.

@OutSorcerer
Copy link
Author

Microsoft finally admitted this is a problem and will fix it (NuGet/Home#4488) , expectantly, in NuGet version 4.0.1, the first update to NuGet 4 after VS 2017 ships.

The cleanest workaround now is to add <RestoreProjectStyle>PackageReference</RestoreProjectStyle> to a legacy project.

However according to Rob Relyea MS will ignore this property after RTM so another workaround is <PackageReference Update="PlaceholderToConvinceThisProjectToGetTransitivePackageReferenceFromProjectReferences"/>.

@moh-hassan
Copy link

moh-hassan commented Jun 26, 2017

As a work around, i modified the the NetStandard project as multi-target:

           <TargetFrameworks>netstandard1.4;net461</TargetFrameworks>

Rebuild the solution and the referenced dll are copied to bin folder of the legacy console project
and it's working fine.
Have a look to that fork(develop):
https://github.com/moh-hassan/nuget-dependencies-of-netstandard-library-bug

@FilipeDominguesGit
Copy link

Any update on this ?

Having the same problem today on a .Net Framework6.1 ConsoleApp referencing a .NetStandard2.0 Class lib project that uses EasyNetQ.

FileNotFoundException: Could not load file or assembly 'EasyNetQ, Version=2.0.4.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

The only way i can get it to work is adding <TargetFrameworks>netstandard2.0;net461</TargetFrameworks> as sugested by @moh-hassan .

Thanks all.

@CyberQin
Copy link

CyberQin commented Dec 8, 2017

Aha,Find a temp workgroud here

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

No branches or pull requests

6 participants