Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Microsoft.NET.Sdk.targets(129,5): error MSB4018: System.TypeLoadException: Could not load type of field 'Microsoft.NET.Build.Tasks.DependencyContextBuilder:_filteredPackages' (12) (expected class 'NuGet.Packaging.Core.PackageIdentity' in assembly 'NuGet.Packaging, Version=5.0.0.6) #7956

Open
knocte opened this issue Apr 4, 2019 · 25 comments

Comments

@knocte
Copy link

commented Apr 4, 2019

Details about Problem

NuGet product used: NuGet.exe
NuGet version (x.x.x.xxx): tested in 4.5.1.4879 and 5.0.0.5923 (affects both)
dotnet.exe --version (if appropriate): 2.1.602 (it was working fine in 2.1.505)
OS version: Ubuntu Linux 18.04
Worked before?: yes, but with previous .NET Core SDK version

Detailed repro steps so we can see the same problem

  1. Install mono from Microsoft deb packages
  2. Install .NET Core SDK 2.1.602 from Microsoft deb packages
  3. Try to build a .NET Standard library that has nuget dependencies.
    Result:
Error MSB4018: The "GenerateDepsFile" task failed unexpectedly. [/builds/DiginexGlobal/geewallet/src/GWallet.Backend.NetStandard/GWallet.Backend.NetStandard.fsproj]
/usr/share/dotnet/sdk/2.1.602/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018: System.TypeLoadException: Could not load type of field 'Microsoft.NET.Build.Tasks.DependencyContextBuilder:_filteredPackages' (12) due to: Could not resolve type with token 01000025 from typeref (expected class 'NuGet.Packaging.Core.PackageIdentity' in assembly 'NuGet.Packaging, Version=5.0.0.6, Culture=neutral, PublicKeyToken=31bf3856ad364e35') assembly:NuGet.Packaging, Version=5.0.0.6, Culture=neutral, PublicKeyToken=31bf3856ad364e35 type:NuGet.Packaging.Core.PackageIdentity member:(null) 

Verbose Logs

verbosity=detail logs: https://gitlab.com/DiginexGlobal/geewallet/-/jobs/190353486

Sample Project

clone https://gitlab.com/knocte/geewallet , switch to the frontend branch, edit the file ./scripts/install_dotnet_sdk_from_microsoft_deb_packages.sh to remove the workaround to install an older version of .NET Core (replacing dotnet-sdk-2.1=2.1.505-1 with just dotnet-sdk-2.1) and compile it with ./configure.sh && make.

@knocte knocte changed the title Microsoft.NET.Sdk.targets(129,5): error MSB4018: System.TypeLoadException: Could not load type of field 'Microsoft.NET.Build.Tasks.DependencyContextBuilder:_filteredPackages' (12) due to: Could not resolve type with token 01000025 from typeref (expected class 'NuGet.Packaging.Core.PackageIdentity' in assembly 'NuGet.Packaging, Version=5.0.0.6 Microsoft.NET.Sdk.targets(129,5): error MSB4018: System.TypeLoadException: Could not load type of field 'Microsoft.NET.Build.Tasks.DependencyContextBuilder:_filteredPackages' (12) (expected class 'NuGet.Packaging.Core.PackageIdentity' in assembly 'NuGet.Packaging, Version=5.0.0.6) Apr 4, 2019

@rrelyea

This comment has been minimized.

Copy link
Contributor

commented Apr 5, 2019

VS4Mac 7.8 and Mono 4.16 (?) and .NET Core SDK 2.1.602 or 2.2.202 have a problem.
We've removed the download for the Mac installers of those 2 SDKs, to avoid this problem.

Longer term, in VS4Mac8.x and Mono 4.18 (?), mono/msbuild should properly enforce loading compatible SDKs. 2.1.602 and 2.2.202 should only be loaded in an msbuild 16.0 environment.

This problem is showing up because we moved all the types from NuGet.Packaging.Core.dll to NuGet.Packaging.dll, and left type forwarders in NuGet.Packaging.Core.dll.
This works ok on full .NET Framework...but fails to work ok in Mono/VS4Mac7.8 -- since Mono cannot support loading NuGet 4.8 and NuGet 5.0. Since NuGet 4.8 loads first (likely to do TFM compat checking for msbuild), NuGet 5.0 cannot be loaded.

We'll try to link to the Mono issues for fixes soon.

@rrelyea rrelyea added this to the 5.0 milestone Apr 5, 2019

@knocte

This comment has been minimized.

Copy link
Author

commented Apr 6, 2019

VS4Mac 7.8 and Mono 4.16 (?)

I'm reproducing this problem with Mono 5.18, the current stable version.

@knocte

This comment has been minimized.

Copy link
Author

commented Apr 6, 2019

We've removed the download for the Mac installers of those 2 SDKs, to avoid this problem.

Can you do the same with Linux please? Remove the .deb files from the server.

@knocte

This comment has been minimized.

Copy link
Author

commented Apr 6, 2019

since Mono cannot support loading NuGet 4.8 and NuGet 5.0. Since NuGet 4.8 loads first (likely to do TFM compat checking for msbuild), NuGet 5.0 cannot be loaded.

So if I use Nuget 4.8, this might workaround the problem? If yes, can you tell me exactly what specific 4.8 version?

@mrward

This comment has been minimized.

Copy link
Member

commented Apr 6, 2019

Right now we are tracking this problem for VS Mac on Developer Community - which @knocte you commented already. Although the error reported here is for .NET Core 3.0 preview 3, and the callstack is slightly different from what is in this github issue, the underlying problem is the same.

There is also an issue filed against .NET Core - dotnet/core#2460 - but it is a problem with Mono's MSBuild - not specific to .NET Core.

You may be able to workaround this by using a global.json file to downgrade the sdk used when building. Otherwise not installing the latest 2.1.602 sdk is another way to avoid this. Also I believe the latest mono 6.3 from master includes an updated MSBuild which should fix this.

@gulando

This comment has been minimized.

Copy link

commented Apr 6, 2019

I have the same problem related with "ResolvePackageDependencies" task failed unexpectedly on my Ubuntu machine.
Ubuntu 18.04
dotnet 2.2.202
Global json file doesn't help too.
My project works under 2.1 version and uninstalling 2.2.202 doesn't help me too.
As you say above you have solved this issue for Mac. Can you please do it for Ubuntu 18.04???

@ruslanen

This comment has been minimized.

Copy link

commented Apr 8, 2019

Same problem:

  Microsoft.NET.Sdk.targets(129, 5): [MSB4018] The "GenerateDepsFile" task failed unexpectedly.
System.TypeLoadException: Could not load type of field 'Microsoft.NET.Build.Tasks.DependencyContextBuilder:_filteredPackages' (12) due to: Could not resolve type with token 01000027 from typeref (expected class 'NuGet.Packaging.Core.PackageIdentity' in assembly 'NuGet.Packaging, Version=5.0.0.6, Culture=neutral, PublicKeyToken=31bf3856ad364e35') assembly:NuGet.Packaging, Version=5.0.0.6, Culture=neutral, PublicKeyToken=31bf3856ad364e35 type:NuGet.Packaging.Core.PackageIdentity member:(null)
  at Microsoft.NET.Build.Tasks.TaskBase.Execute () [0x00000] in <c5e0e1dbe29a4fae9ad829d4b52ccc8b>:0 
  at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00029] in <57d75baabd164eb5a523fbc6e3599a2d>:0 
  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) [0x001f6] in <57d75baabd164eb5a523fbc6e3599a2d>:0 

OS:

[root@alpha-fedora bin]# cat /etc/fedora-release 
Fedora release 29 (Twenty Nine)

NET Core SDK

[root@alpha-fedora bin]# dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   2.2.202
 Commit:    8a7ff6789d

Runtime Environment:
 OS Name:     fedora
 OS Version:  29
 OS Platform: Linux
 RID:         fedora.29-x64
 Base Path:   /usr/share/dotnet/sdk/2.2.202/

Host (useful for support):
  Version: 2.2.3
  Commit:  6b8ad509b6

.NET Core SDKs installed:
  2.1.602 [/usr/share/dotnet/sdk]
  2.2.202 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.9 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.3 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.9 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.3 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.9 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.3 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Mono:

[root@alpha-fedora bin]# mono --version
Mono JIT compiler version 5.18.1.0 (tarball Fri Mar 15 15:48:09 UTC 2019)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none
        Misc:          softdebug 
        Interpreter:   yes
        LLVM:          yes(600)
        Suspend:       preemptive
        GC:            sgen (concurrent by default)

(not repeated under Windows)

@knocte

This comment has been minimized.

Copy link
Author

commented Apr 8, 2019

You may be able to workaround this by using a global.json file to downgrade the sdk used when building.

How does that global.json work? I thought that apt installations wouldn't depend on this? I for now am workarounding this problem by using an older version of .NETCore, yes, but downloading the .deb file manually.

@mrward

This comment has been minimized.

Copy link
Member

commented Apr 8, 2019

A global.json can be used to specify a particular sdk version when building with msbuild.

@knocte

This comment has been minimized.

Copy link
Author

commented Apr 8, 2019

A global.json can be used to specify a particular sdk version when building with msbuild.

Ah I see, however I'm not sure that would help me because I'm actually just installing .NET Core SDK as a workaround to this other bug: mono/mono#10570

@Huck

This comment has been minimized.

Copy link

commented Apr 11, 2019

We have been having the same issue in Ubuntu 18.04 and 2.2 for a week now. Its a very crippling bug unless we downgrade to 105. any fix in sight?

@edouard-chevalier

This comment has been minimized.

Copy link

commented Apr 16, 2019

This bug prevents from updating to latest dotnet sdk on ubuntu 16.04.
looking forward for a fix.

@ermshiperete

This comment has been minimized.

Copy link

commented May 28, 2019

I hope this gets fixed soon. It's very annoying. The confusing version numbers where .NET SDK and .NET Core version numbers don't match doesn't help either... (https://developercommunity.visualstudio.com/content/problem/213229/the-current-net-sdk-does-not-support-targeting-net.html)

What eventually worked for me:

sudo apt install dotnet-sdk-2.2=2.2.105-1
sudo apt-mark hold dotnet-sdk-2.2

Since I also sometimes use Synaptic to update, I had to "Lock Version" there as well.

rolfbjarne added a commit to xamarin/xamarin-macios that referenced this issue May 30, 2019

rolfbjarne added a commit to xamarin/xamarin-macios that referenced this issue May 31, 2019

@mattleibow

This comment has been minimized.

Copy link

commented Jun 15, 2019

I also noticed this on Ubuntu 18.04 and msbuild 16 with .net core 2.2.300. I tried a few of the earlier versions of the dotnet-sdk, but had to drop down to 2.2.105.

Not sure if this helps.

@knocte

This comment has been minimized.

Copy link
Author

commented Jun 16, 2019

Right now we are tracking this problem for VS Mac on Developer Community (https://developercommunity.visualstudio.com/content/problem/481018/resolvepackageassets-task-failed.html)

Matt, that issue in visualstudio.com has been marked as resolved, I guess because VS4Mac8.1 is out now in the stable channel, which has a fix for this. However, this covers only the part of the story when building from the IDE, not from the command line.

Also I believe the latest mono 6.3 from master includes an updated MSBuild which should fix this.

Any chance this fix could make into the 5.18 stable branch of mono? The stable channel in macOS is still on version 5.18.1.28 and I doubt an update to 6.3 will happen soon.

@mrward

This comment has been minimized.

Copy link
Member

commented Jun 16, 2019

.NET Core 2.1.602 should be OK with Mono 5.18.1.28.

There is a matrix of supported VS Mac and .NET Core versions documented:

https://docs.microsoft.com/en-us/visualstudio/mac/net-core-support?view=vsmac-2019

I believe there is a plan to produce a some similar document, as shown above, but for Mono.

As of today the current VS Mac to Mono mappings are:

  • VS Mac 8.0 => Mono 5.18.1.3
  • VS Mac 8.1 => Mono 5.18.1.28
  • VS Mac 8.2 => Mono 6.0.0.296

As far as I am aware there are no plans to make further MSBuild changes to Mono 5.18.1.

knocte added a commit to knocte/geewallet that referenced this issue Jun 17, 2019

scripts: remove workaround that used an older version of .NETCore
The version of mono from the stable channel that is pulled from the
deb repository seems to be now 5.20.1.19 ([1]), and according to
this comment from Matt[2] it should work with the new version of
.NETCore 2.1.x that should be provided now via deb repos too.

[1] (tarball Thu Apr 11 09:02:17 UTC 2019)
[2] NuGet/Home#7956 (comment)
@knocte

This comment has been minimized.

Copy link
Author

commented Jun 17, 2019

.NET Core 2.1.602 should be OK with Mono 5.18.1.28.

I just tested mono 5.20.1.19 (tarball Thu Apr 11 09:02:17 UTC 2019) with .NETCore 2.1.700 and still fails. Full build log here: https://gitlab.com/knocte/geewallet/-/jobs/232398170

@mrward

This comment has been minimized.

Copy link
Member

commented Jun 17, 2019

Not sure what the status is of Mono 5.20 since it is on a different branch. Possibly MSBuild has not been updated on that branch. /cc @radical

Not seeing that error on the Mac. If you do something similar to the following what version do you get?

monodis --assembly /path/to/mono/msbuild/Current/bin/NuGet.Packaging.dll | grep Version

Also what does msbuild -version show?

Mono 5.18.1.28 uses NuGet 5.0 which should be OK with NuGet 5.1 in the .NET Core 2.1.700 SDK. MSBuild with Mono 5.18.1.28 is: 16.0.459+g5b35a69a2e for Mono

  /usr/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018: The "GenerateDepsFile" task failed unexpectedly. 
/usr/share/dotnet/sdk/2.1.700/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018: System.TypeLoadException: Could not load type of field 'Microsoft.NET.Build.Tasks.DependencyContextBuilder:_filteredPackages' (12) due to: Could not resolve type with token 01000025 from typeref (expected class 'NuGet.Packaging.Core.PackageIdentity' in assembly 'NuGet.Packaging, Version=5.1.0.5, Culture=neutral, PublicKeyToken=31bf3856ad364e35') assembly:NuGet.Packaging, Version=5.1.0.5, Culture=neutral, PublicKeyToken=31bf3856ad364e35 
@knocte

This comment has been minimized.

Copy link
Author

commented Jun 17, 2019

Not sure what the status is of Mono 5.20

The stable channel of the apt repository is yielding this version.

Also what does msbuild -version show?

This:

Microsoft (R) Build Engine version 16.0.0.0 for Mono
Copyright (C) Microsoft Corporation. All rights reserved.

16.0.0.0

If you do something similar to the following what version do you get?

There are many files called this way, which one should I monodis?:

/usr/lib/mono/msbuild/15.0/bin/NuGet.Packaging.Core.dll
/usr/lib/mono/msbuild/15.0/bin/Sdks/Microsoft.NET.Sdk/tools/net46/NuGet.Packaging.Core.dll
/usr/lib/mono/msbuild/15.0/bin/Sdks/Microsoft.NET.Sdk/tools/net46/NuGet.Packaging.dll
/usr/lib/mono/msbuild/15.0/bin/NuGet.Packaging.dll
@mrward

This comment has been minimized.

Copy link
Member

commented Jun 17, 2019

I ran monodis on NuGet.Packaging.dll. However I can see from that list of files that MSBuild is not up to date there. With Mono 5.18.1.28 there is no NuGet.Packaging.Core.dll. So I suspect NuGet 4.8 is being used.

@ermshiperete

This comment has been minimized.

Copy link

commented Jun 17, 2019

Yes. Mono 5.20.1.19 seems to include NuGet 4.8:

$ monodis --assembly /usr/lib/mono/msbuild/15.0/bin/NuGet.Packaging.dll | grep Version
Version:       4.8.0.1

scottinet added a commit to kuzzleio/sdk-csharp that referenced this issue Jun 18, 2019

Initialize unit tests project (#11)
# Description

Initialize unit tests on this repo, with a bit of tooling, code coverage calculation and reporting.

Necessary refactor: API controller now receive a Kuzzle API interface (`IKuzzleApi`) instead of a Kuzzle instance, because mocking can only be done with interfaces or abstract classes.

⚠️ this project cannot be built nor tested using monodevelop due to current compatibility problems between dotnet-core and msbuild. Read the README documentation to build this SDK from the CLI.
See NuGet/Home#7956
@knocte

This comment has been minimized.

Copy link
Author

commented Jun 18, 2019

Yes. Mono 5.20.1.19 seems to include NuGet 4.8:

I confirm what @ermshiperete sees:

$ monodis --assembly /usr/lib/mono/msbuild/15.0/bin/NuGet.Packaging.Core.dll | grep Version
Version:       4.8.0.1
$ monodis --assembly /usr/lib/mono/msbuild/15.0/bin/Sdks/Microsoft.NET.Sdk/tools/net46/NuGet.Packaging.Core.dll | grep Version
Version:       4.7.0.5
$ monodis --assembly /usr/lib/mono/msbuild/15.0/bin/Sdks/Microsoft.NET.Sdk/tools/net46/NuGet.Packaging.dll | grep Version
Version:       4.7.0.5
$ monodis --assembly /usr/lib/mono/msbuild/15.0/bin/NuGet.Packaging.dll | grep Version
Version:       4.8.0.1

With Mono 5.18.1.28 there is no NuGet.Packaging.Core.dll

You mean in macOS? Because I'm guessing the scripts that were used to package mono 5.18 on the apt repository are the same ones that package the 5.20 version.

So I suspect NuGet 4.8 is being used.

There must be a difference somewhere around how mono is packaged on Linux vs macOS, for them to have different versions of nuget. I'm guessing we have to ping @directhex to help us fix this?

Just FTR, these are the versions on macOS:

$ monodis --assembly /Applications/Visual\ Studio.app/Contents/Resources/lib/monodevelop/AddIns/MonoDevelop.PackageManagement/NuGet.Packaging.dll | grep Version
Version:       5.0.2.0
$ monodis --assembly /Library/Frameworks/Mono.framework/Versions/5.18.1/lib/mono/msbuild/Current/bin/NuGet.Packaging.dll | grep Version
Version:       5.0.2.0
$ monodis --assembly /Library/Frameworks/Mono.framework/Versions/5.18.1/lib/mono/msbuild/Current/bin/Sdks/Microsoft.NET.Sdk/tools/net472/NuGet.Packaging.dll | grep Version
Version:       5.0.0.5
$ monodis --assembly /usr/local/share/dotnet/sdk/2.1.700/NuGet.Packaging.dll | grep Version
Version:       5.1.0.5
@ermshiperete

This comment has been minimized.

Copy link

commented Jun 18, 2019

Looking at the repo that I guess is used to build Linux packages it seems that the problem is fixed but the package not released yet:

$ monodis --assembly nuget-support/tasks-targets/NuGet.Packaging.dll | grep Version
Version:       5.0.0.5

It seems that the fixed package is currently in beta. @directhex any estimates when the fixed package version will be released?

@knocte

This comment has been minimized.

Copy link
Author

commented Jun 18, 2019

It seems that the fixed package is currently in beta. @directhex any estimates when the fixed package version will be released?

If that nuget version is already released in the stable channel (not beta) for macOS, shouldn't Linux be in sync? Why is macOS's NuGet 5.x while Linux's is 4.x, but Linux's mono is 5.20.x while macOS's is 5.18.x? Food for thought :)

@rhaley-starfish

This comment has been minimized.

Copy link

commented Jul 5, 2019

While by no means a proper fix, I have two work arounds in MonoDevelop 7.8.2 on Ubuntu 18 using dotnet core 2.2.300. Note that I will never be running a Mono project in this environment so I haven't tested that this doesn't break Mono:

  1. I re-wrote the /usr/bin/msbuild command:
#!/bin/sh
DOTNET_DIR=/usr/share/dotnet/sdk/2.2.300
CMD="dotnet"
MSBUILD_CMD="$CMD $DOTNET_DIR/MSBuild.dll"

$MSBUILD_CMD $@

and secondly I overwrote the Mono Nuget* files with the files from my dotnet core sdk:

cd /usr/lib/mono/msbuild/15.0/bin/
sudo cp /usr/share/dotnet/sdk/2.2.300/NuGet* .

rolfbjarne added a commit to xamarin/xamarin-macios that referenced this issue Jul 11, 2019

[xcode11][tests] Provision dotnet for the sample tests. Fixes xamarin…
…/maccore#1811. (#6473) (#6488)

* [sampletester] Use dotnet v2.2.1XX if available. (#6185)

Works around NuGet/Home#7956.

* [tests] Provision dotnet for the sample tests. Fixes xamarin/maccore#1811. (#6473)

Also synchronize configuration file creation to not run into threading issues.

Fixes xamarin/maccore#1811.

rolfbjarne added a commit to xamarin/xamarin-macios that referenced this issue Jul 12, 2019

rolfbjarne added a commit to xamarin/xamarin-macios that referenced this issue Aug 13, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
10 participants
You can’t perform that action at this time.