question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:12
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

11reactions
moh-hassancommented, 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

2reactions
FilipeDominguesGitcommented, Nov 30, 2017

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Netstandard dependency System.IO.FileNotFoundException
I advise you to right click on the solution, and go to 'manage NuGet packages', then go to the consolidate tab and resolve...
Read more >
Why not able to load netstandard.dll when creating new ...
dll you are trying to load is a reference assembly that which cannot be loaded for runtime on .NET Framework as pointed out...
Read more >
Run ASP.NET Core Apps on the .NET Framework
Many of Microsoft's core .NET Standard 2.0 packages have been reported to have runtime Assembly loading issues that throw FileNotFoundException "Could not load ......
Read more >
NET Standard
However, if you want to share code between .NET Framework and any other .NET implementation, such as .NET Core, your library should target...
Read more >
Error after upgrading to 2023.1.314 in UI for ASP.NET MVC
I used the upgrade wizard to download the latest version and I'm getting this error message on pages that have the components:Could not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found