To be absolutely clear, THIS IS NOT A DUPLICATE of millions of similar errors.
But this error is not new, there's something wrong with the package.
This is the most horrific bug I've ever encountered in my like 30 years experience.
First of all, my application using Newtonsoft.Json package works both with Debug and Release configurations.
Then I publish it with OneFile and ReadyToRun options.
When I try to run it I get: System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'.
Now - the package is linked into my exe file. Like 15 other packages that works. That mechanism works even with Windows and Linux native libraries. The package I see in my dependencies is version 13.0.1.
This is the current version. My entire solution does not have a single string "13.0.0". The only references to Newtonsoft.Json package are to version "13.0.1".
But when launched from my single file build - Newtonsoft.Json decides to throw a FileNotFoundException.
I'm banging my head against the wall. WTF is going on? I had similar error long, long time ago, on .NET Framework 4.5. My new app is on .NET 5.0. It has no weird package version redirection stuff. It just uses nuget for packages, they are all defined in one place in my project file.
Is it a bug in Newtonsoft.Json, or somewhere else?
Obviously, I won't paste millions of lines of my production code here. The code is simple, in one place it does something like var x = new JObject() and it throws the exception.
The only way to reproduce it is to create a new C# project on .NET 5.0, add Newtonsoft.Json package reference, use any method from that package, then make 1 file publish of it and try to run it.
I'm not even sure if it will trigger the bug on other computers, because last time I've seen this error it happened only on one of my Windows servers, and not other machines.