Nerdbank.gitversioning: GetBuildVersion task fails with `System.MissingMethodException` when building with Mono MSBuild on macOS

Created on 8 Mar 2019  路  23Comments  路  Source: dotnet/Nerdbank.GitVersioning

Version information

Component|Version
-|-
Nerdbank.GitVersioning|2.3.125
Mono.Framework|5.16.0
Visual Studio for Mac|7.8.2 (build 1)
MSBuild|16.0.40-preview+ge6c3a1f9e4
.NET Core SDK|2.2.104
macOS|10.14.3 (Mojave)

Repro Steps

  1. Create a new .NET Standard class library in Visual Studio for Mac
  2. Add the Nerdbank.GitVersioning NuGet package
  3. Create a simple version.json file (see below)
  4. Build > Build All (or msbuild /t:restore && msbuild from a Terminal outside VSMac)

(Note: I also tried installing the nbgv tool and doing nbgv install.. the same error/behaviour surfaces. I don't think this is a solution/project configuration issue.)

Expected behaviour
The build is successful 馃槃

Actual behaviour
Build error 馃槩

System.MissingMethodException: Method not found: void Newtonsoft.Json.Converters.StringEnumConverter.set_NamingStrategy

Curiously, when using the .NET Core CLI toolchain then the build succeeds (dotnet build rather than msbuild, the latter being what VSMac uses).

Build output

/Users/<user>/.nuget/packages/nerdbank.gitversioning/2.3.125/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018: The "Nerdbank.GitVersioning.Tasks.GetBuildVersion" task failed unexpectedly.
/Users/<user>/.nuget/packages/nerdbank.gitversioning/2.3.125/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018: System.MissingMethodException: Method not found: void Newtonsoft.Json.Converters.StringEnumConverter.set_NamingStrategy(Newtonsoft.Json.Serialization.NamingStrategy)
/Users/<user>/.nuget/packages/nerdbank.gitversioning/2.3.125/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:   at Nerdbank.GitVersioning.VersionFile.TryReadVersionJsonContent (System.String jsonContent) [0x00000] in <60a3cf7da8fe4c9d80305de7a36e73b4>:0 
/Users/<user>/.nuget/packages/nerdbank.gitversioning/2.3.125/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:   at Nerdbank.GitVersioning.VersionFile.GetVersion (LibGit2Sharp.Commit commit, System.String repoRelativeProjectDirectory) [0x000eb] in <60a3cf7da8fe4c9d80305de7a36e73b4>:0 
/Users/<user>/.nuget/packages/nerdbank.gitversioning/2.3.125/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:   at Nerdbank.GitVersioning.VersionOracle..ctor (System.String projectDirectory, LibGit2Sharp.Repository repo, LibGit2Sharp.Commit head, Nerdbank.GitVersioning.ICloudBuild cloudBuild, System.Nullable`1[T] overrideBuildNumberOffset, System.String projectPathRelativeToGitRepoRoot) [0x000a8] in <60a3cf7da8fe4c9d80305de7a36e73b4>:0 
/Users/<user>/.nuget/packages/nerdbank.gitversioning/2.3.125/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:   at Nerdbank.GitVersioning.VersionOracle.Create (System.String projectDirectory, System.String gitRepoDirectory, Nerdbank.GitVersioning.ICloudBuild cloudBuild, System.Nullable`1[T] overrideBuildNumberOffset, System.String projectPathRelativeToGitRepoRoot) [0x0001f] in <60a3cf7da8fe4c9d80305de7a36e73b4>:0 
/Users/<user>/.nuget/packages/nerdbank.gitversioning/2.3.125/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:   at Nerdbank.GitVersioning.Tasks.GetBuildVersion.ExecuteInner () [0x000c5] in <b9250c5c0ff64d0facfbd2c9542bc589>:0 
/Users/<user>/.nuget/packages/nerdbank.gitversioning/2.3.125/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:   at MSBuildExtensionTask.ContextAwareTask.Execute () [0x0005e] in <b9250c5c0ff64d0facfbd2c9542bc589>:0 
/Users/<user>/.nuget/packages/nerdbank.gitversioning/2.3.125/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00023] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/msbuild-15/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs:573 
/Users/<user>/.nuget/packages/nerdbank.gitversioning/2.3.125/build/Nerdbank.GitVersioning.targets(63,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) [0x001f6] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/msbuild-15/src/Build/BackEnd/Components/RequestBuilder/TaskBuilder.cs:784 
    0 Warning(s)
    1 Error(s)

version.json

{
  "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
  "version": "1.0-beta",
  "publicReleaseRefSpec": [
    "^refs/heads/master$"
  ]
}

Project file

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Nerdbank.GitVersioning">
      <Version>2.3.125</Version>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>
</Project>

Solution file

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "netstandardlib", "netstandardlib\netstandardlib.csproj", "{B1FA5F49-E24B-4D73-9FA5-E961A67811CB}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
        Release|Any CPU = Release|Any CPU
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {B1FA5F49-E24B-4D73-9FA5-E961A67811CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {B1FA5F49-E24B-4D73-9FA5-E961A67811CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {B1FA5F49-E24B-4D73-9FA5-E961A67811CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {B1FA5F49-E24B-4D73-9FA5-E961A67811CB}.Release|Any CPU.Build.0 = Release|Any CPU
    EndGlobalSection
EndGlobal

Most helpful comment

If you use package version 2.3.38 then the issue does not reproduce, meaning that it is something that has changed since then to 2.3.125.

All 23 comments

If you use package version 2.3.38 then the issue does not reproduce, meaning that it is something that has changed since then to 2.3.125.

We are consistently getting this on our project ReactiveUI, downgrading to 2.3.38 is a workaround

I'm getting the same issue here (Building with Visual Studio for Mac).

The method it's complaining about looks to be a recent addition to Newtonsoft.Json, so possibly down to the package version being updated in https://github.com/AArnott/Nerdbank.GitVersioning/commit/c147f3723ec1f10e9ce1288be1a22cd7faa1a9f4#diff-574082642ffdd7d9cbcbe853e627a843 ? (sounds like it's trying to use the old version of the assembly that is missing the new method?)

I'm hitting the same issue.

@radical ^ I think we need to update the NewtonSoft.Json in Mono's MSBuild

ikdasm /Library/Frameworks/Mono.framework/Versions/Current/lib/mono/msbuild/Current/bin/Newtonsoft.Json.dll | grep FileVersion
  .custom instance void [System.Runtime]System.Reflection.AssemblyFileVersionAttribute::.ctor(string) = ( 01 00 0B 39 2E 30 2E 31 2E 31 39 38 31 33 00 00 ) // ...9.0.1.19813..

If the newtonsoft.json assembly version changed (from 11 to 12) then why would mono's msbuild's version of newtonsoft.json matter? If it shipped 11 or older, and I want 12, I should still get 12. Unless either mono doesn't follow the same binding rules that the CLR does, or mono's msbuild.exe.config redirects 12 to 11, which would be bad.

@japj do you recall why you upgraded newtonsoft.json in #296? A simple solution might be to revert back to v11.

I'm noticing a bunch of bugs with the mono msbuild with it having one version which prevents the newer one being used. Eg https://github.com/NuGet/Home/issues/7956#issuecomment-480427346 for example required me to downgrade my nuget package version on a tool recently.

Yes, Mono's binding rules have historically been simpler. IIRC unless the relatively recently added strict mode is enabled, then only one dll with a particular name can be loaded regardless of version. The MSBuild.dll.config doesn't appear to have any binding redirects either.

That copy of Newtonsoft.Json.dll is being added as a dependency of the nuget build tasks. I can't update it separately.
re:strict-mode, it isn't enabled yet, but I'm testing regular builds with that.

@mhutch How do you enable the strict mode?

What version of newtonsoft.json does mono msbuild ship? I don't mind downgrading for now to unblock folks.

Is it referencing the newer newtonsoft.json that causes issues, or just using the new NamingStrategy property? (the change in https://github.com/AArnott/Nerdbank.GitVersioning/pull/296/commits/845badf6be5a3faa56250839cfcdfb64110455c2) ? (the version used by Mono apparently predating that property being there)

Apparently mono has no problem with us referencing a higher assembly version. But I refuse to just remove our use of the property while continuing to reference the newer version, as that is a very fragile situation.

The FileVersion appears to be 9.0.1.19813

@radical do we know why the NuGet tasks use such an old version?

Would someone who can repro the problem please help verify #362 is effective by downloading the nupkg from the PR build artifacts, install it, and see if it works?

that build seems to work for me in Visual Studio for Mac (8.2)

Works in our CI build environment that was failing before.

I had this issue with a Xamarin project build. Thinking it might be the fix I needed, too.

Great. I'll merge and push to nuget.org then.

This is fixed in v2.3.183.

Was this page helpful?
0 / 5 - 0 ratings