1

I've NuGet package (.Net Standard 2.0) that references Newtonsoft.Json v13.0.1 by PackageReference (What's called the new way). All looks good when packing it. Installing in the VSIX project shows that Newtonsoft will be downloaded as well and builds successfully. The error happens when VSIX project (.Net Full 4.8) runs and the method that uses Newtonsoft breaks with the message Could not load file or assembly 'Newtonsoft.JSON, Version=13.0.0.0, ...' or one of its dependencies. The system cannot find the file specified.

I've tried different approaches (none of them worked):

  • Manually copying Newtonsoft.Json.dll to libs folder in downloaded package.
  • Forcing installing Newtonsoft.JSON in the VSIX project.

The NuGet project can be found here and the VSIX project here.

Any ideas?

Update:

I've changed from Newtonsoft to System.Text.Json to give a try and the error didn't change.

gandarez
  • 2,609
  • 4
  • 34
  • 47
  • I found a previous post similar to your situation as attached. Try the approaches suggested there? Good luck. https://stackoverflow.com/questions/38671641/could-not-load-file-or-assembly-newtonsoft-json-version-9-0-0-0-culture-neutr/38715898#38715898 – Jacqui Huang Aug 23 '21 at 01:03
  • @JacquiHuang I've added the source code for the NuGet package as well the VSIX project. – gandarez Aug 24 '21 at 00:22

1 Answers1

0

So from the error message, the issue is that the NuGet package, related files or dependencies cannot be found/loaded. So the cause should be the specific NuGet package does not exist, or is not located in the specific folder/directory, or the path is not pointed out. Or there are several different versions of the same NuGet packages used by mixed.

Since not sure of your project/solution structure, I assume you have a .net standard based project, and you packed it into a NuGet package. Also you installed it in a VSIX project, and in this VSIX project, you used the method from Newtonsoft.json NuGet package which is referenced in your .net standard project.

First thing you can try is manually copy the correct version of Newtonsoft.Json.dll(normally in C:\Users\[user name]\.nuget\packages\newtonsoft.json\13.0.1\lib\...) into your VSIX project folder. The VSIX project folder directory should be like this XXXX\XXXX\[your project folder name]\bin\Debug(or Release, depend on which mode you are using).

Other suggestions:

Go to Tools > Options > NuGet Package Manager > General > click and check Allow NuGet to download missing packages and Automatically check for missing packages during build in Visual Studio checkboxes, and then click Clear All NuGet Cache(s) button > OK. After that rebuild and rerun your VSIX project.

If above don’t work, could you please share some steps with me to reproduce your issue and check further :)

Tianyu
  • 895
  • 3
  • 7
  • I've added the source code for the NuGet package as well the VSIX project. – gandarez Aug 24 '21 at 00:22
  • I could successfully run the VSIX project that you shared. Looks like there is no issue with your codes/settings, and perhaps cache affect? Have you tried to run your VSIX project on another machine? Besides, please clear NuGet cache and project cache(`bin`, `obj`, `.vs` folders). Also [repair VS](https://learn.microsoft.com/en-us/visualstudio/install/repair-visual-studio?view=vs-2019#how-to-repair). – Tianyu Aug 27 '21 at 13:48