I ran my .Net Framework 4.7.1 project through the .NET Upgrade Assistant to upgrade it to .NET 5 and have been left with the following two errors that are both the same except for the roslyn versioning (3.11 and 4.0).
Error CS8032 An instance of analyzer System.Text.Json.SourceGeneration.JsonSourceGenerator cannot be created from C:\Users\myAccount\.nuget\packages\system.text.json\6.0.5\analyzers\dotnet\roslyn3.11\cs\System.Text.Json.SourceGeneration.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
Error CS8032 An instance of analyzer System.Text.Json.SourceGeneration.JsonSourceGenerator cannot be created from C:\Users\myAccount\.nuget\packages\system.text.json\6.0.5\analyzers\dotnet\roslyn4.0\cs\System.Text.Json.SourceGeneration.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
If I add a nuget package reference to System.Text.Json version 6.0.0, the second error goes away, leaving me with
Error CS8032 An instance of analyzer System.Text.Json.SourceGeneration.JsonSourceGenerator cannot be created from C:\Users\myAccount\.nuget\packages\system.text.json\6.0.5\analyzers\dotnet\roslyn3.11\cs\System.Text.Json.SourceGeneration.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
I have nuget package references to NHibernate 5.3.12 and Serilog 2.11.0 and no others. I am not sure how to diagnose what could be causing the problem for this project and get it to compile. Any suggestions are appreciated.
So it appears that the addition of the unnecessary System.Text.Json nuget package was a red herring.
It turned out that I was using Visual Studio 2019 (the same IDE we have been using throughout or development of the product pre-upgrade to .NET 5). When I opened the solution in Visual Studio 2022, the underlying errors were actually displayed, easily resolved, and now the solution compiles as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With