'The "ResolvePackageAssets" task failed unexpectedly - System.TypeLoadException

I am trying to set up visual studio 2019 on macos (10.14.3), but when attempting to build a default web MVC project I get this dependency error:

    Target _CheckForNETCoreSdkIsPreview:
    /usr/local/share/dotnet/sdk/3.0.100-preview3-010431/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(151,5): message NETSDK1057: You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview
Target ResolvePackageAssets:
    /usr/local/share/dotnet/sdk/3.0.100-preview3-010431/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(228,5): error MSB4018: The "ResolvePackageAssets" task failed unexpectedly.
    /usr/local/share/dotnet/sdk/3.0.100-preview3-010431/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(228,5): error MSB4018: System.TypeLoadException: Could not resolve type with token 0100003f from typeref (expected class 'NuGet.Packaging.Core.PackageDependency' in assembly 'NuGet.Packaging, Version=5.0.0.4, Culture=neutral, PublicKeyToken=31bf3856ad364e35')
    /usr/local/share/dotnet/sdk/3.0.100-preview3-010431/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(228,5): error MSB4018:   at Microsoft.NET.Build.Tasks.ResolvePackageAssets+CacheWriter.GetPlatformPackageExclusions () [0x000d7] in <9524e6fbf1724027a475d15b01fab866>:0 
    /usr/local/share/dotnet/sdk/3.0.100-preview3-010431/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(228,5): error MSB4018:   at Microsoft.NET.Build.Tasks.ResolvePackageAssets+CacheWriter..ctor (Microsoft.NET.Build.Tasks.ResolvePackageAssets task, System.IO.Stream stream) [0x0009b] in <9524e6fbf1724027a475d15b01fab866>:0 
    /usr/local/share/dotnet/sdk/3.0.100-preview3-010431/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(228,5): error MSB4018:   at Microsoft.NET.Build.Tasks.ResolvePackageAssets+CacheReader.CreateReaderFromDisk (Microsoft.NET.Build.Tasks.ResolvePackageAssets task, System.Byte[] settingsHash) [0x0003a] in <9524e6fbf1724027a475d15b01fab866>:0 
    /usr/local/share/dotnet/sdk/3.0.100-preview3-010431/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(228,5): error MSB4018:   at Microsoft.NET.Build.Tasks.ResolvePackageAssets+CacheReader..ctor (Microsoft.NET.Build.Tasks.ResolvePackageAssets task) [0x00015] in <9524e6fbf1724027a475d15b01fab866>:0 
    /usr/local/share/dotnet/sdk/3.0.100-preview3-010431/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(228,5): error MSB4018:   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups () [0x00000] in <9524e6fbf1724027a475d15b01fab866>:0 
    /usr/local/share/dotnet/sdk/3.0.100-preview3-010431/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(228,5): error MSB4018:   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore () [0x00018] in <9524e6fbf1724027a475d15b01fab866>:0 
    /usr/local/share/dotnet/sdk/3.0.100-preview3-010431/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(228,5): error MSB4018:   at Microsoft.NET.Build.Tasks.TaskBase.Execute () [0x00000] in <9524e6fbf1724027a475d15b01fab866>:0 
    /usr/local/share/dotnet/sdk/3.0.100-preview3-010431/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(228,5): error MSB4018:   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00023] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-10/external/bockbuild/builds/msbuild-15/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs:573 
    /usr/local/share/dotnet/sdk/3.0.100-preview3-010431/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(228,5): error MSB4018:   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask (Microsoft.Build.BackEnd.ITaskExecutionHost taskExecutionHost, Microsoft.Build.BackEnd.Logging.TaskLoggingContext taskLoggingContext, Microsoft.Build.BackEnd.TaskHost taskHost, Microsoft.Build.BackEnd.ItemBucket bucket, Microsoft.Build.BackEnd.TaskExecutionMode howToExecuteTask) [0x00212] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-10/external/bockbuild/builds/msbuild-15/src/Build/BackEnd/Components/RequestBuilder/TaskBuilder.cs:784 
Done building target "ResolvePackageAssets" in project "TestingApp.csproj" -- FAILED.

Done building project "TestingApp.csproj" -- FAILED.

Build FAILED.

I also tried to run it from terminal with dotnet run and it works, but I cannot use Visual Studio. Thanks.



Solution 1:[1]

Just remove BIN and OBJ directories from the project and rebuild.

Solution 2:[2]

Try from command line:

  • dotnet clean
  • dotnet build

It worked for me. Take a look here for more info

Solution 3:[3]

Root cause :-

This error due to Nuget packages version compatibility different in projects(Shared project,iOS Project,Android Projects).

Solution:-

1.Update the each Nuget packages where shows update version in front of nuget package.

2.Clean solution.

3.Build Solution,

Solution 4:[4]

In my case. Go to C:\Program Files(x86)\Microsoft Visual Studio\Shared then create a new folder name is "NugetPackages"

Build and run the program again, Problem is fixed.

Solution 5:[5]

Just had the same problem. Reason was, in Project Options of main-project Build-General the Target Framework was changed, don't know why. For my project it should be Xamarin.Mac Full Net 4.7.2, but for whatever reason it now was Xamarin.Mac Modern. Changed back to Full and everything was fine again.

I remember, it happened already again a while ago, after another update of VS Mac. As Xamarin user for many years in the meantime I know, that many Xamarin-Updates are breaking things, which were fine before.

Solution 6:[6]

Try following steps on your project/lib :

  1. if you are working multiple directory structure then apply full rights on it
  2. if you are working with older version of NuGet then update them with latest or compatible version
  3. if still not working then delete bin folder and execute step 1 and 2 again.

it's worked for me.

Solution 7:[7]

Open Visual Studio with elevated permission (Run As Administrator) Then try clean and rebuild.

Solution 8:[8]

I found (under VS2022 using .Net6) that all I had to do was create an empty folder under:

C:\Program Files (x86)\ComponentOne\Winforms Edition\bin\v5

and then perform a project rebuild via "Build/Rebuild" in the VS2022 menu.

Solution 9:[9]

In my case running Visual Studio with elevated privilidges was the solution.

Solution 10:[10]

For me, non of the solutions here worked, but a Visual Studio software update did the job.

It generally happens when the Mono's MSBuild - that is being used by Visual Studio to build the project - does not support the SDK version you're using, which can make many packages that are (e.g.) built for .NET 5 and requires Nuget 5 Packaging to fail to build with the MSBuild.

You would typically get one of the following errors:

  • Microsoft.NET.Sdk.targets(124, 5): [MSB4018] The "PACKAGE_NAME" task failed unexpectedly.
  • Microsoft.PackageDependencyResolution.targets(234, 5): [MSB4018] The "ResolvePackageAssets" task failed unexpectedly.

So installing or changing to the compatible MSBuild, or changing the SDK should usually fix the problem.

You can find more helpful information here:

Solution 11:[11]

Just rebuild the project. It automatically cleans and restores the required files then it build the project