Skip to content

System.MissingMethodException: Method not found: 'Void NuGet.Commands.RestoreRequest..ctor( ... )'. #1538

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

Closed
LordMike opened this issue Nov 22, 2018 · 16 comments

Comments

@LordMike
Copy link

So. This is odd. This worked a few days ago, on both Windows and Linux (ubuntu - docker), but now it works only on Linux.

We're running .NET SDK 2.1.500 (aka 2.1.6), with GitVersionTask 4.0.1-beta1-47. Without GitVersionTask, all builds - but with it we get:

> dotnet build
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

MSBUILD : Task factory warning NMSBT010: There is a mismatch between SDK NuGet version (4.9.0) and the NuGet version the task factory was compiled against (4.8.0). There might occur some exotic errors. [C:\Src\Project.csproj]
MSBUILD : Task factory error NMSBT001: Exception in initialization: System.MissingMethodException: Method not found: 'Void NuGet.Commands.RestoreRequest..ctor(NuGet.ProjectModel.PackageSpec, NuGet.Commands.RestoreCommandProviders, NuGet.Protocol.Core.Types.SourceCacheContext, NuGet.Common.ILogger)'. [C:\Src\Project.csproj]
MSBUILD : Task factory error NMSBT001:    at UtilPack.NuGet.BoundRestoreCommandUser.PerformRestore(ValueTuple`2[] targets, CancellationToken token) [C:\Src\Project.csproj]
MSBUILD : Task factory error NMSBT001:    at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) [C:\Src\Project.csproj]
MSBUILD : Task factory error NMSBT001:    at UtilPack.NuGet.BoundRestoreCommandUser.PerformRestore(ValueTuple`2[] targets, CancellationToken token) [C:\Src\Project.csproj]
MSBUILD : Task factory error NMSBT001:    at UtilPack.NuGet.BoundRestoreCommandUser.RestoreIfNeeded(CancellationToken token, ValueTuple`2[] packageInfo) [C:\Src\Project.csproj]
MSBUILD : Task factory error NMSBT001:    at UtilPack.NuGet.MSBuild.NuGetTaskRunnerFactory.Initialize(String taskName, IDictionary`2 parameterGroup, String taskBody, IBuildEngine taskFactoryLoggingHost) [C:\Src\Project.csproj]
C:\Users\MichaelBisbjerg\.nuget\packages\gitversiontask\4.0.1-beta1-47\build\functionality\GitVersionMultiTargetBuild.targets(6,5): error MSB4175: The task factory "UtilPack.NuGet.MSBuild.NuGetTaskRunnerFactory" could not be loaded from the assembly "C:\Users\MichaelBisbjerg\.nuget\packages\utilpack.nuget.msbuild\2.7.0\build\\netcoreapp1.1\UtilPack.NuGet.MSBuild.dll". Object reference not set to an instance of an object. [C:\Src\Project.csproj]

Updating UtilPack.NuGet.MSBuild to 2.9.0 gives:

> dotnet build
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

MSBUILD : Task factory error NMSBT000: Failed to load actual task factory assembly System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\MichaelBisbjerg\.nuget\packages\utilpack.nuget.msbuild\2.9.0\buildMultiTargeting\build\netcoreapp1.1'. [C:\Src\Project.csproj]
MSBUILD : Task factory error NMSBT000:    at System.IO.Enumeration.FileSystemEnumerator`1.CreateDirectoryHandle(String path, Boolean ignoreNotFound) [C:\Src\Project.csproj]
MSBUILD : Task factory error NMSBT000:    at System.IO.Enumeration.FileSystemEnumerator`1..ctor(String directory, EnumerationOptions options) [C:\Src\Project.csproj]
MSBUILD : Task factory error NMSBT000:    at System.IO.Enumeration.FileSystemEnumerable`1..ctor(String directory, FindTransform transform, EnumerationOptions options) [C:\Src\Project.csproj]
MSBUILD : Task factory error NMSBT000:    at System.IO.Enumeration.FileSystemEnumerableFactory.UserFiles(String directory, String expression, EnumerationOptions options) [C:\Src\Project.csproj]
MSBUILD : Task factory error NMSBT000:    at System.IO.Directory.InternalEnumeratePaths(String path, String searchPattern, SearchTarget searchTarget, EnumerationOptions options) [C:\Src\Project.csproj]
MSBUILD : Task factory error NMSBT000:    at UtilPack.NuGet.MSBuild.NuGetTaskRunnerFactory.GetNewestAvailableTaskFactoryVersion(String thisDir, String thisName) [C:\Src\Project.csproj]
MSBUILD : Task factory error NMSBT000:    at UtilPack.NuGet.MSBuild.NuGetTaskRunnerFactory..ctor(). [C:\Src\Project.csproj]
C:\Users\MichaelBisbjerg\.nuget\packages\gitversiontask\4.0.1-beta1-47\build\functionality\GitVersionMultiTargetBuild.targets(6,5): error MSB4175: The task factory "UtilPack.NuGet.MSBuild.NuGetTaskRunnerFactory" could not be loaded from the assembly "C:\Users\MichaelBisbjerg\.nuget\packages\utilpack.nuget.msbuild\2.9.0\buildMultiTargeting\\..\build\netcoreapp1.1\UtilPack.NuGet.MSBuild.dll". Object reference not set to an instance of an object. [C:\Src\Project.csproj]

On an Ubuntu linux (docker), the build is fine.

@dazinator
Copy link
Member

dazinator commented Nov 23, 2018

as per the second case above, I think this may have been introduced in a recent beta version, a new beta version will be available shortly, it should fix these issues.

@dazinator dazinator added the bug label Nov 23, 2018
@LordMike
Copy link
Author

LordMike commented Nov 23, 2018

With 4.0.1-beta1-49, I get:

MSBUILD : Task factory error NMSBT000: Failed to load actual task factory assembly System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\MichaelBisbjerg\.nuget\packages\utilpack.nuget.msbuild\2.9.0\buildMultiTargeting\build\netcoreapp1.1'.
MSBUILD : Task factory error NMSBT000:    at System.IO.Enumeration.FileSystemEnumerator`1.CreateDirectoryHandle(String path, Boolean ignoreNotFound) [C:\Src\Libraries\PeParser\PeParser.csproj]
MSBUILD : Task factory error NMSBT000:    at System.IO.Enumeration.FileSystemEnumerator`1..ctor(String directory, EnumerationOptions options) [C:\Src\Libraries\PeParser\PeParser.csproj]
MSBUILD : Task factory error NMSBT000:    at System.IO.Enumeration.FileSystemEnumerable`1..ctor(String directory, FindTransform transform, EnumerationOptions options) [C:\Src\Libraries\PeParser\PeParser.csproj]
MSBUILD : Task factory error NMSBT000:    at System.IO.Enumeration.FileSystemEnumerableFactory.UserFiles(String directory, String expression, EnumerationOptions options) [C:\Src\Libraries\PeParser\PeParser.csproj]
MSBUILD : Task factory error NMSBT000:    at System.IO.Directory.InternalEnumeratePaths(String path, String searchPattern, SearchTarget searchTarget, EnumerationOptions options) [C:\Src\Libraries\PeParser\PeParser.csproj]
MSBUILD : Task factory error NMSBT000:    at UtilPack.NuGet.MSBuild.NuGetTaskRunnerFactory.GetNewestAvailableTaskFactoryVersion(String thisDir, String thisName) [C:\Src\Libraries\PeParser\PeParser.csproj]
MSBUILD : Task factory error NMSBT000:    at UtilPack.NuGet.MSBuild.NuGetTaskRunnerFactory..ctor(). [C:\Src\Libraries\PeParser\PeParser.csproj]
C:\Users\MichaelBisbjerg\.nuget\packages\gitversiontask\4.0.1-beta1-49\build\functionality\GitVersionBuild.targets(6,5): error MSB4175: The task factory "UtilPack.NuGet.MSBuild.NuGetTaskRunnerFactory" could not be loaded from the assembly "C:\Users\MichaelBisbjerg\.nuget\packages\utilpack.nuget.msbuild\2.9.0\build\\netcoreapp1.1\UtilPack.NuGet.MSBuild.dll". Object reference not set to an instance of an object. [C:\Src\Libraries\PeParser\PeParser.csproj]

The directory does not exist. I have the following files in C:\Users\MichaelBisbjerg\.nuget\packages\utilpack.nuget.msbuild\2.9.0:

$ find -type f
./.nupkg.metadata
./.signature.p7s
./build/net46/Newtonsoft.Json.dll
./build/net46/NuGet.Commands.dll
./build/net46/NuGet.Common.dll
./build/net46/NuGet.Configuration.dll
./build/net46/NuGet.Credentials.dll
./build/net46/NuGet.DependencyResolver.Core.dll
./build/net46/NuGet.Frameworks.dll
./build/net46/NuGet.LibraryModel.dll
./build/net46/NuGet.Packaging.Core.dll
./build/net46/NuGet.Packaging.dll
./build/net46/NuGet.ProjectModel.dll
./build/net46/NuGet.Protocol.dll
./build/net46/NuGet.Versioning.dll
./build/net46/System.ValueTuple.dll
./build/net46/UtilPack.NuGet.MSBuild.dll
./build/netcoreapp1.1/UtilPack.NuGet.MSBuild.dll
./build/netcoreapp1.1/UtilPack.NuGet.MSBuild.NuGet.4.3.0.dll
./build/netcoreapp1.1/UtilPack.NuGet.MSBuild.NuGet.4.4.0.dll
./build/netcoreapp1.1/UtilPack.NuGet.MSBuild.NuGet.4.5.0.dll
./build/netcoreapp1.1/UtilPack.NuGet.MSBuild.NuGet.4.6.0.dll
./build/netcoreapp1.1/UtilPack.NuGet.MSBuild.NuGet.4.7.0.dll
./build/netcoreapp1.1/UtilPack.NuGet.MSBuild.NuGet.4.8.0.dll
./build/netcoreapp1.1/UtilPack.NuGet.MSBuild.NuGet.4.9.0.dll
./build/UtilPack.NuGet.MSBuild.props
./buildMultiTargeting/UtilPack.NuGet.MSBuild.props
./utilpack.nuget.msbuild.2.9.0.nupkg
./utilpack.nuget.msbuild.2.9.0.nupkg.sha512
./utilpack.nuget.msbuild.nuspec

@arturcic
Copy link
Member

@LordMike is it related to #1503 ?

@dazinator
Copy link
Member

From what I can tell from the logs shown above, the util pack msbuild taskfactory is throwing an exception in it's constructor, looking for a directory that doesn't exist: "Could not find a part of the path 'C:\Users\MichaelBisbjerg.nuget\packages\utilpack.nuget.msbuild\2.9.0\buildMultiTargeting\build\netcoreapp1.1'."

@LordMike can you confirm if this is happening in the latest "4.0.1-beta1-50" release? I know @stazz made some changes so perhaps it was fixed.

@LordMike
Copy link
Author

As I mentioned in the other issue, #1503, I can now run builds on my desktop where I previously had an issue. I'll report back if we see this again.

@arturcic
Copy link
Member

Closing the issue as it was solved in #1503

@LordMike
Copy link
Author

LordMike commented Nov 27, 2018

A coworker got this:

C:\Users\USER\.nuget\packages\gitversiontask\4.0.1-beta1-50\build\functionality\GitVersionMultiTargetBuild.targets(6,5): error MSB4175: The task factory "UtilPack.NuGet.MSBuild.NuGetTaskRunnerFactory" could not be loaded from the assembly "C:\Users\USER\.nuget\packages\utilpack.nuget.msbuild\2.9.1\buildMultiTargeting\\..\build\netcoreapp1.1\UtilPack.NuGet.MSBuild.dll". Assembly with same name is already loaded [G:\Src\Project.csproj]

His C:\Users\USER\.nuget\packages\utilpack.nuget.msbuild\2.9.1 directory has this:

./.signature.p7s
./build/net46/Newtonsoft.Json.dll
./build/net46/NuGet.Commands.dll
./build/net46/NuGet.Common.dll
./build/net46/NuGet.Configuration.dll
./build/net46/NuGet.Credentials.dll
./build/net46/NuGet.DependencyResolver.Core.dll
./build/net46/NuGet.Frameworks.dll
./build/net46/NuGet.LibraryModel.dll
./build/net46/NuGet.Packaging.Core.dll
./build/net46/NuGet.Packaging.dll
./build/net46/NuGet.ProjectModel.dll
./build/net46/NuGet.Protocol.dll
./build/net46/NuGet.Versioning.dll
./build/net46/System.ValueTuple.dll
./build/net46/UtilPack.NuGet.MSBuild.dll
./build/netcoreapp1.1/UtilPack.NuGet.MSBuild.dll
./build/netcoreapp1.1/UtilPack.NuGet.MSBuild.NuGet.4.3.0.dll
./build/netcoreapp1.1/UtilPack.NuGet.MSBuild.NuGet.4.4.0.dll
./build/netcoreapp1.1/UtilPack.NuGet.MSBuild.NuGet.4.5.0.dll
./build/netcoreapp1.1/UtilPack.NuGet.MSBuild.NuGet.4.6.0.dll
./build/netcoreapp1.1/UtilPack.NuGet.MSBuild.NuGet.4.7.0.dll
./build/netcoreapp1.1/UtilPack.NuGet.MSBuild.NuGet.4.8.0.dll
./build/netcoreapp1.1/UtilPack.NuGet.MSBuild.NuGet.4.9.0.dll
./build/UtilPack.NuGet.MSBuild.props
./buildMultiTargeting/UtilPack.NuGet.MSBuild.props
./utilpack.nuget.msbuild.2.9.1.nupkg
./utilpack.nuget.msbuild.2.9.1.nupkg.sha512
./utilpack.nuget.msbuild.nuspec

EDIT

Also from the same computer, now with full stack:

C:\Users\USER\.nuget\packages\gitversiontask\4.0.1-beta1-50\build\functionality\GitVersionMultiTargetBuild.targets(6,5): error MSB4175: The task factory "UtilPack.NuGet.MSBuild.NuGetTaskRunnerFactory" could not be loaded from the assembly "C:\Users\USER\.nuget\packages\utilpack.nuget.msbuild\2.9.1\buildMultiTargeting\\..\build\netcoreapp1.1\UtilPack.NuGet.MSBuild.dll". Object reference not set to an instance of an object. [C:\Src\Project.csproj]
 
Build FAILED.

MSBUILD : Task factory error NMSBT000: Failed to load actual task factory assembly System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\USER\.nuget\packages\utilpack.nuget.msbuild\2.9.1\buildMultiTargeting\build\netcoreapp1.1'. [C:\Src\Project.csproj]
MSBUILD : Task factory error NMSBT000:    at System.IO.Enumeration.FileSystemEnumerator`1.CreateDirectoryHandle(String path, Boolean ignoreNotFound) [C:\Src\Project.csproj]
MSBUILD : Task factory error NMSBT000:    at System.IO.Enumeration.FileSystemEnumerator`1..ctor(String directory, EnumerationOptions options) [C:\Src\Project.csproj]
MSBUILD : Task factory error NMSBT000:    at System.IO.Enumeration.FileSystemEnumerable`1..ctor(String directory, FindTransform transform, EnumerationOptions options) [C:\Src\Project.csproj]
MSBUILD : Task factory error NMSBT000:    at System.IO.Enumeration.FileSystemEnumerableFactory.UserFiles(String directory, String expression, EnumerationOptions options) [C:\Src\Project.csproj]
MSBUILD : Task factory error NMSBT000:    at System.IO.Directory.InternalEnumeratePaths(String path, String searchPattern, SearchTarget searchTarget, EnumerationOptions options) [C:\Src\Project.csproj]
MSBUILD : Task factory error NMSBT000:    at UtilPack.NuGet.MSBuild.NuGetTaskRunnerFactory.GetAllAvailableTaskFactoryVersions(String thisDir, String thisName) [C:\Src\Project.csproj]
MSBUILD : Task factory error NMSBT000:    at UtilPack.NuGet.MSBuild.NuGetTaskRunnerFactory..ctor(). [C:\Src\Project.csproj]
C:\Users\USER\.nuget\packages\gitversiontask\4.0.1-beta1-50\build\functionality\GitVersionMultiTargetBuild.targets(6,5): error MSB4175: The task factory "UtilPack.NuGet.MSBuild.NuGetTaskRunnerFactory" could not be loaded from the assembly "C:\Users\USER\.nuget\packages\utilpack.nuget.msbuild\2.9.1\buildMultiTargeting\\..\build\netcoreapp1.1\UtilPack.NuGet.MSBuild.dll". Object reference not set to an instance of an object. [C:\Src\Project.csproj]

@arturcic
Copy link
Member

@stazz could you please have a look?

@stazz
Copy link
Contributor

stazz commented Nov 27, 2018

The error messages

  • Failed to load actual task factory assembly System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\MichaelBisbjerg.nuget\packages\utilpack.nuget.msbuild\2.9.0\buildMultiTargeting\build\netcoreapp1.1'.` )
  • Failed to load actual task factory assembly System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\USER.nuget\packages\utilpack.nuget.msbuild\2.9.1\buildMultiTargeting\build\netcoreapp1.1'.

hint that for some reason the path resolution misses "one level up" step between the buildMultiTargeting and build components when loading the DLL. It fails because of course, the file does not exist there. I'll investigate this when I get home and back to you guys.

I have to say, I've never seen this kind of error before. :) Is there something special with the environment? Any information about the .NET SDK version or maybe some magic environment variables possibly affecting assembly resolution?

@stazz
Copy link
Contributor

stazz commented Nov 27, 2018

I can't reproduce this at least with the projects that contain <TargetFramework> and <TargetFrameworks> elements. Do these errors happen only for <TargetFrameworks> multi-targeting projects?

Looking at stack trace, it goes into GetAllAvailableTaskFactoryVersions of UtilPack, which then calls Directory.EnumerateFiles( thisDir, thisName + ".*.dll", SearchOption.TopDirectoryOnly ), which then throws DirectoryNotFoundException. The documentation says it happens when the first parameter referes to a directory which does not exist, which totally makes sense.

The thisDir is the result of Path.GetDirectoryName of the Path.GetFullPath( new Uri( this.GetType().GetTypeInfo().Assembly.CodeBase ).LocalPath ). The CodeBase property of the Assembly object refers to the original path where assembly was loaded, but for some reason it does not exist. So suddenly, this makes no sense at all anymore. :)

This error seems really weird to me, and my gut feeling says there is something wrong with the MSBuild properties here. I noticed that Infrastructure.props file always includes $(MSBuildThisFileDirectory)../../../utilpack.nuget.msbuild/$(UtilPackVersion)/build/UtilPack.NuGet.MSBuild.props, however it never includes the $(UtilPackVersion)/buildMultiTargeting/UtilPack.NuGet.MSBuild.props file. Is there some specific reason for this?

Overall, I could work out exactly what is wrong and what is going on with all the <Import>ing and MSBuild properties with a project repro, along with .NET SDK version and the OS which is used to run the dotnet command.

@LordMike
Copy link
Author

LordMike commented Nov 28, 2018

@stazz my coworker installed 2.2.100-preview3. It works without it.

So. Everything is as intended, but we'll have the exact same issues in sdk-2.2

@stazz
Copy link
Contributor

stazz commented Nov 28, 2018

I guess the 2.2.100-preview3 has maybe NuGet 4.10.0? You guys really like the bleeding edge! :D

I'll check what it's like in 2.2, not sure if I'll be able to actually compile it until the next version is released on NuGet... Unless I do some pretty epic hacking. :)

@LordMike
Copy link
Author

Yea, sorry about that. Hadn't checked his SDK version.

From our side, the issue is minor. Once 2.2 is out, we'll re-evaluate. :)

@ckarras
Copy link

ckarras commented May 29, 2019

So what's the solution? As a user of NuGet, what do I need to update to fix this?

I have .Net Core 2.2 (dotnet.exe = 2.2.300), Visual Studio 2019.

I also have this warning:
MSBUILD : Task factory warning NMSBT010: There is a mismatch between SDK NuGet version (5.1.0) and the NuGet version the task factory was compiled against (4.8.0). There might occur some exotic errors

How do I update either the "SDK NuGet version" or something else whose version was compiled against an appropriate version of the task factory?

@stazz
Copy link
Contributor

stazz commented May 29, 2019

@ckarras The "SDK NuGet version" is the version of NuGet that is shipped with .NET Core SDK. It is not the same as the version of the .NET Core SDK itself.

I'm not maintainer of this repo, but pull request #1677 was just merged, which will invoke the tasks in such way that this kind of error is no longer even possible. I think it is supposed to be coming to version 5.0.0 of the GitVersion.

@ckarras
Copy link

ckarras commented May 29, 2019

@stazz Thanks, I got two possible solutions from this information:

  • Option 1. Reference UtilPack.NuGet.MSBuild version 2.9.1 (PackageReference in csproj file), instead of relying on the indirect reference to an older version of UtilPack.NuGet.MSBuild though the reference to GitVersionTask. Make sure the PackageReference for UtilPack.NuGet.MSBuild is before the one for GitVersionTask
  • Option 2. Upgrade to latest prerelease of GitVersionTask (5.0.0-beta3-4) and ensure there's no reference to UtilPack.NuGet.MSBuild.

For both options, the changes must be done in the project (csproj) file and in any referenced project files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants