Wednesday, 23 December 2020

ASP.NET Core: FileNotFoundException: Could not load file or assembly

 I had a complex solution with multiple projects and NuGet references.

To debug one troublesome Nuget package, I removed the Nuget reference and added a project reference so I could step through the code.

However when the website ran, it would throw the error:

FileNotFoundException: Could not load file or assembly <troublesome assembly>

Investigation

  1. procmon.exe indicated that the website wasn't even loading the assembly - or trying to
  2. <website>.deps.json didn't have a reference to the assembly
  3. Visual Studio Resharper was showing the following popup:


Conclusions

The problem was that I had added the project to the solution, but the project was located in a folder outside of the root solution folder. By taking a copy inside of the root solution folder and re-adding the reference, the <website>.deps.json then included the reference and the assembly loaded.

  1. Check your <website>.deps.json 
  2. Use ProcMon
  3. Make sure that the project referenced is inside your solution folder.


No comments:

Post a comment