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

GetBuildVersion task fails with System.MissingMethodException when building with Mono MSBuild on macOS #306

Closed
mjcheetham opened this issue Mar 8, 2019 · 23 comments

Comments

@mjcheetham
Copy link

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
@mjcheetham
Copy link
Author

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.

@glennawatson
Copy link

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

@Numpsy
Copy link
Contributor

Numpsy commented Mar 19, 2019

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 c147f37#diff-574082642ffdd7d9cbcbe853e627a843 ? (sounds like it's trying to use the old version of the assembly that is missing the new method?)

@azchohfi
Copy link
Contributor

azchohfi commented May 9, 2019

I'm hitting the same issue.

@mhutch
Copy link

mhutch commented Jun 19, 2019

@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..

mhutch added a commit to mhutch/MiniEditor that referenced this issue Jun 19, 2019
@AArnott
Copy link
Collaborator

AArnott commented Jun 19, 2019

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.

@AArnott
Copy link
Collaborator

AArnott commented Jun 19, 2019

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

@glennawatson
Copy link

I'm noticing a bunch of bugs with the mono msbuild with it having one version which prevents the newer one being used. Eg NuGet/Home#7956 (comment) for example required me to downgrade my nuget package version on a tool recently.

@mhutch
Copy link

mhutch commented Jun 19, 2019

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.

@radical
Copy link
Member

radical commented Jun 19, 2019

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.

@glennawatson
Copy link

@mhutch How do you enable the strict mode?

@mhutch
Copy link

mhutch commented Jun 19, 2019

@glennawatson see mono/mono#9225

@AArnott
Copy link
Collaborator

AArnott commented Jun 19, 2019

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

@Numpsy
Copy link
Contributor

Numpsy commented Jun 19, 2019

Is it referencing the newer newtonsoft.json that causes issues, or just using the new NamingStrategy property? (the change in 845badf) ? (the version used by Mono apparently predating that property being there)

@AArnott
Copy link
Collaborator

AArnott commented Jun 19, 2019

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.

@mhutch
Copy link

mhutch commented Jun 19, 2019

The FileVersion appears to be 9.0.1.19813

@mhutch
Copy link

mhutch commented Jun 19, 2019

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

@AArnott
Copy link
Collaborator

AArnott commented Jun 19, 2019

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?

@Numpsy
Copy link
Contributor

Numpsy commented Jun 19, 2019

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

@glennawatson
Copy link

Works in our CI build environment that was failing before.

@tiwahu
Copy link

tiwahu commented Jun 19, 2019

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

@AArnott
Copy link
Collaborator

AArnott commented Jun 19, 2019

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

@AArnott
Copy link
Collaborator

AArnott commented Jun 19, 2019

This is fixed in v2.3.183.

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

8 participants