microsoft / MSBuildLocator

An API to locate MSBuild assemblies from an installed Visual Studio location. Use this to ensure that calling the MSBuild API will use the same toolset that a build from Visual Studio or msbuild.exe would.
Other
212 stars 83 forks source link

Msbuild failed: Newtonsoft.Json, Version=13.0.0.0 #150

Closed chanakya-svt closed 10 months ago

chanakya-svt commented 2 years ago

I am using a code analysis tool called Roslynator. After upgrading to .NET6, I am getting the following error when I run analysis on the solution.

I was directed to here by the author of Roslynator based on the discussion

Following is the error I am facing:

Error Log ``` Msbuild failed when processing the file '~/net6/RoslynatorTest/RoslynatorTest.csproj' with message: /usr/local/share/dotnet/sdk/6.0.101/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets: (129, 5): The "ResolveAppHosts" task failed unexpectedly. System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. Could not find or load a specific file. (0x80131621) File name: 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' ---> System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly) at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath) at System.Reflection.Assembly.LoadFrom(String assemblyFile) at Microsoft.Build.Locator.MSBuildLocator.<>c__DisplayClass15_0.g__TryLoadAssembly|3(AssemblyName assemblyName) at Microsoft.Build.Locator.MSBuildLocator.<>c__DisplayClass15_0.b__2(AssemblyLoadContext _, AssemblyName assemblyName) at System.Runtime.Loader.AssemblyLoadContext.GetFirstResolvedAssemblyFromResolvingEvent(AssemblyName assemblyName) at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingEvent(AssemblyName assemblyName) at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingResolvingEvent(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName) at NuGet.RuntimeModel.JsonRuntimeFormat.ReadRuntimeGraph(TextReader textReader) at NuGet.RuntimeModel.JsonRuntimeFormat.ReadRuntimeGraph(Stream stream) at NuGet.RuntimeModel.JsonRuntimeFormat.ReadRuntimeGraph(String filePath) at Microsoft.NET.Build.Tasks.RuntimeGraphCache.GetRuntimeGraph(String runtimeJsonPath) at Microsoft.NET.Build.Tasks.ResolveAppHosts.GetHostItem(String runtimeIdentifier, List`1 knownAppHostPacksForTargetFramework, List`1 packagesToDownload, String hostNameWithoutExtension, String itemName, Boolean isExecutable, Boolean errorIfNotFound) at Microsoft.NET.Build.Tasks.ResolveAppHosts.ExecuteCore() at Microsoft.NET.Build.Tasks.TaskBase.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) ```

Environment: .NET: v6.0 OS: macOS Montery v12.2 Example repo: https://github.com/chanakya-svt/RoslynatorTest

Steps to Reproduce:

  1. Clone the above repo and restore
  2. install roslynator command line dotnet tool install -g roslynator.dotnet.cli
  3. run roslynator analyze -v diag

Note: The same setup works without an errors for .net5.0

Please redirect if this is not the correct place for this issue.

josefpihrt commented 2 years ago

Any update on this?

lars-berger commented 2 years ago

Also running into this error when running roslynator analyze -v diag.

Environment: Windows 10 Build 19044 .NET Core SDK v6.0.202

Error log ``` Msbuild failed when processing the file 'C:\Users\larsb\repos\glazewm-net-6\GlazeWM.Domain\GlazeWM.Domain.csproj' with message: C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets: (267, 5): Error reading assets file: Error loading lock file 'C:\Users\larsb\repos\glazewm-net-6\GlazeWM.Domain\obj\project.assets.json' : Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. Could not find or load a specific file. (0x80131621) ```
nlubisch commented 2 years ago

Are there any news? I'm also stumbling over this problem.

Forgind commented 1 year ago

Does this use MSBuildLocator at all? From what you're doing, it looks like you need to.

YuliiaKovalova commented 10 months ago

Hi @nlubisch , @chanakya-svt,

Could you tell us, if this issue is still relevant to you?

YuliiaKovalova commented 10 months ago

feel free to reopen it if it is still relevant.