I met System.IO.FileNotFoundException when using DLLs indirectly referenced.
A .NET framework 4.8 project references a .NET standard 2.0 project, and the .NET standard project references a NuGet package (Newtonsoft.Json). A .NET standard method uses a class in the NuGet package, and the method is called by the .NET framework project. When calling the method, System.IO.FileNotFoundException is thrown saying it can't load assembly Newtonsoft.Json.
Why does this happen and how can I fix it?
I added the NuGet package in the main .NET framework project and it worked, but I think this is not an elegant way to fix this problem.
In .NET standard:
public class Class1
{
public static void Run()
{
var x = new JsonSerializer();
}
}
In .NET framework:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Class1.Run();
}
}
Error message: System.IO.FileNotFoundException:“未能加载文件或程序集“Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”或它的某一个依赖项。系统找不到指定的文件。”
(Translation: System.IO.FileNotFoundException:"Can't load file or assembly "Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" or one of its dependencies. The system can't find the specified file."