Having a weird issue all of a sudden - my visual studio 2022 solution refuses to build, as several projects suddenly and unaccountably report similar errors, looking like this:
The "ResolvePackageAssets" task failed unexpectedly.
System.TypeInitializationException: The type initializer for 'NuGet.ProjectModel.JsonUtility' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
at NuGet.ProjectModel.JsonUtility..cctor()
--- End of inner exception stack trace ---
at NuGet.ProjectModel.JsonUtility.UseNewtonsoftJsonForParsing(IEnvironmentVariableReader environmentVariableReader, Boolean bypassCache)
at NuGet.ProjectModel.LockFileFormat.Read(Stream stream, ILogger log, String path, IEnvironmentVariableReader environmentVariableReader, Boolean bypassCache, LockFileReadFlags flags)
at NuGet.ProjectModel.LockFileUtilities.<>c__DisplayClass1_0.<GetLockFile>b__0(FileStream stream, String path)
at NuGet.Common.FileUtility.SafeReadT
at NuGet.ProjectModel.LockFileUtilities.GetLockFile(String lockFilePath, ILogger logger, LockFileReadFlags flags)
at Microsoft.NET.Build.Tasks.LockFileCache.LoadLockFile(String path)
at Microsoft.NET.Build.Tasks.LockFileCache.GetLockFile(String path)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter..ctor(ResolvePackageAssets task)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader.CreateReaderFromDisk(ResolvePackageAssets task, Byte[] settingsHash)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader..ctor(ResolvePackageAssets task)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups()
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore()
at Microsoft.NET.Build.Tasks.TaskBase.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
At the same time, Visual Studio setup executable fails to run silently. No amount of cleaning, rebuilding, deleting caches, deleting bin/obj/packages folders, or restarting visual studio has helped so far. Installing .NET SDK 6 has not helped (and I didn't need it before, when it built successfully - and the projects in question didn't change at all - so why?)
The precipitating incident seems to have been swapping between git branches across an attempt to upgrade my project from .net framework 4.6.2 to .net core 8. I have swapped branches without issue many times before, but now the build is in a bad state regardless of branch (and the projects with the error were unaffected by the upgrade - one of them is .net core 5, one of them is .netstandard 2.0, etc.)
Running "dotnet nuget locals all --clear" did not help either.
Any other ideas? Anyone seen something like this before? Thank you so much for any help! I am dead in the water without being able to build my projects!