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

TypeInitializationException on OSX #222

Closed
rgmills opened this issue Sep 11, 2018 · 11 comments
Closed

TypeInitializationException on OSX #222

rgmills opened this issue Sep 11, 2018 · 11 comments
Assignees

Comments

@rgmills
Copy link

rgmills commented Sep 11, 2018

Hello,

We recently updated to 2.2.13 (from 2.1.23) and are encountering an issue on OSX.

Tools:

  • Visual Studio for Mac
  • dotnet sdk v2.1.401

Below is the error output:

Target GetBuildVersion:
    /Users/username/.nuget/packages/nerdbank.gitversioning/2.2.13/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018: The "Nerdbank.GitVersioning.Tasks.GetBuildVersion" task failed unexpectedly.
    /Users/username/.nuget/packages/nerdbank.gitversioning/2.2.13/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018: System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: lib/osx/libgit2-6311e88.dylib
    /Users/username/.nuget/packages/nerdbank.gitversioning/2.2.13/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:   at (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods.git_libgit2_init()
    /Users/username/.nuget/packages/nerdbank.gitversioning/2.2.13/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:   at LibGit2Sharp.Core.NativeMethods.LoadNativeLibrary () [0x00000] in <b59d5da32f8541b2a767004d8bddc22b>:0 
    /Users/username/.nuget/packages/nerdbank.gitversioning/2.2.13/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:   at LibGit2Sharp.Core.NativeMethods..cctor () [0x00045] in <b59d5da32f8541b2a767004d8bddc22b>:0 
    /Users/username/.nuget/packages/nerdbank.gitversioning/2.2.13/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:    --- End of inner exception stack trace ---
    /Users/username/.nuget/packages/nerdbank.gitversioning/2.2.13/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:   at LibGit2Sharp.Core.Proxy.git_libgit2_opts_set_search_path (LibGit2Sharp.ConfigurationLevel level, System.String path) [0x00000] in <b59d5da32f8541b2a767004d8bddc22b>:0 
    /Users/username/.nuget/packages/nerdbank.gitversioning/2.2.13/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:   at LibGit2Sharp.GlobalSettings.SetConfigSearchPaths (LibGit2Sharp.ConfigurationLevel level, System.String[] paths) [0x0001a] in <b59d5da32f8541b2a767004d8bddc22b>:0 
    /Users/username/.nuget/packages/nerdbank.gitversioning/2.2.13/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:   at Nerdbank.GitVersioning.GitExtensions.OpenGitRepo (System.String pathUnderGitRepo) [0x00012] in <150882c73d494e8384ad79d7674b0ae0>:0 
    /Users/username/.nuget/packages/nerdbank.gitversioning/2.2.13/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) [0x00017] in <150882c73d494e8384ad79d7674b0ae0>:0 
    /Users/username/.nuget/packages/nerdbank.gitversioning/2.2.13/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:   at Nerdbank.GitVersioning.Tasks.GetBuildVersion.ExecuteInner () [0x000c5] in <a9ad9b18f9d14576b838941f05d31209>:0 
    /Users/username/.nuget/packages/nerdbank.gitversioning/2.2.13/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:   at MSBuildExtensionTask.ContextAwareTask.Execute () [0x0005e] in <a039684190264706bf075ac0ee99291f>:0 
    /Users/username/.nuget/packages/nerdbank.gitversioning/2.2.13/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00023] in /_/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs:631 
    /Users/username/.nuget/packages/nerdbank.gitversioning/2.2.13/build/Nerdbank.GitVersioning.targets(63,5): error MSB4018:   at Microsoft.Build.BackEnd.TaskBuilder+<ExecuteInstantiatedTask>d__26.MoveNext () [0x00212] in /_/src/Build/BackEnd/Components/RequestBuilder/TaskBuilder.cs:787 
Done building target "GetBuildVersion" in project "MyProject.csproj" -- FAILED.

Let me know if there is any additional information I can provide.

@AArnott
Copy link
Collaborator

AArnott commented Sep 11, 2018

Thanks for your report. What version of OSX are you testing on?

@AArnott AArnott added the bug label Sep 11, 2018
@AArnott AArnott self-assigned this Sep 11, 2018
@rgmills
Copy link
Author

rgmills commented Sep 11, 2018

Hi @AArnott , we're using High Sierra 10.13.2

@frankbuckley
Copy link

Also on OSX 10.13.6.

Nerdbank.GitVersioning 2.1.84 does not exhibit the problem.

@frankbuckley
Copy link

Oddly, dotnet build ... works (with 2.2.13) but msbuild … does not.

@AArnott
Copy link
Collaborator

AArnott commented Sep 20, 2018

@rgmills What about you? Are you using dotnet build or msbuild?

Isn't msbuild only present when mono is installed? I haven't actively tested NB.GV with mono. It's quite the task just to make sure NB.GV works on .NET Framework, and all three OS's with .NET Core. Adding mono to the mix... that's a lot of work.

If dotnet build works, can you switch to using that?

@frankbuckley
Copy link

Yes - that's msbuild on Mono. Can't switch for Xamarin iOS projects because the SDK is not available to dotnet build. I guess the same applies to Xamarin Android projects on Mac OS, but not sure since we build our Android projects on Windows.

If you have any pointers to where I might look, I would be happy to try to figure out what has changed between 2.1.84 and 2.2.13 to break Mono msbuild. Is there a way I can debug the msbuild task on a Mac? Also, how/where does TargetsPath get set?

@AArnott
Copy link
Collaborator

AArnott commented Sep 20, 2018

Thanks, @frankbuckley. TargetsPath gets set here:

https://github.com/AArnott/Nerdbank.GitVersioning/blob/d0bbbacfe34e9540572e5747893f2897c892d64a/src/Nerdbank.GitVersioning.Tasks/build/Nerdbank.GitVersioning.targets#L70

I have no idea how to debug mono msbuild on Mac. On Windows I'll sometimes add a Debugger.Launch() call to my msbuild task which pops up a JIT debugger dialog that I can use. I don't know if something similar is available on Mac.

Between 2.1.84 and 2.2.13 the primary change was adding support for Ubuntu 18 and other more recent linux distros. It was a lot of trial-and-error changes to try to get everything working at once. It was a delicate balancing act. So if we can get this to work for mono, we'll need to revalidate on all the other platforms we support. I'm building up my prowess at Azure Pipelines build validations that include many different target OSs and versions that should help with that.

Yes, whatever you can do to help investigate would be much appreciated.

@frankbuckley
Copy link

@AArnott - I have made a start at figuring it out.

My first thought was this was the problem - in that it will return lib/win32 on Mono OSX: https://github.com/AArnott/Nerdbank.GitVersioning/blob/d0bbbacfe34e9540572e5747893f2897c892d64a/src/NerdBank.GitVersioning/GitExtensions.cs#L357-L364

However, changing that did not fix the DllNotFoundException.

The only thing I have found so far that 'fixes' (works around) the problem it is to put copies of the libraries back under MSBuildFull.

I have confirmed this does not break dotnet build and fixes the DllNotFoundException on Mono msbuild on Mac OS X 10.13.6 (MS Build 15.7.224 on Mono 5.12.0) and Ubuntu 18.04.1 (MS Build 15.6.0.0 on Mono 5.14.0. I have not tested Mono on Windows. Both dotnet build and .NET Framework msbuild on Windows work OK with this change.

I have been playing around with a test project that can be used to test with dotnet and msbuild with local build artifacts. This could be used in CI builds to validate on multiple platforms. However, to build on OSX and Linux, Nerdbank.GitVersioning.LKG needs to be a version that works on those platforms. How do I make one?

@AArnott
Copy link
Collaborator

AArnott commented Sep 23, 2018

Ah, yes that's great that putting those DLLs back solve the problem. I remember I removed them because they didn't appear to be needed any more -- not because they were causing any problem other than making the package bigger. I wonder if we can avoid the extra copy of DLLs by just adjusting the .targets files somehow... but I'm OK to bring them back if that's the only way we know how to go.

I appreciate all the validation you've done as well.

Regarding the LKG, that was a one-off change of source code where I added a PackageId property to the project and packed it, then pushed that package. I think it was that simple, but as you can tell, it was a while back that I did it. It certainly warrants a refresher now, particular for the sake of the regression testing you mentioned. Let's get your existing fix in first (can you send a PR?) and then I can spin another LKG and then if you can prepare the change to get the tests running on multiple OSs smoke test it on each build system, that would be awesome.

@dasMulli
Copy link

👏 @frankbuckley highly appreciate you working on this since I just started running into this myself - unable to use vscode on Mac to work on projects at the moment.

@AArnott AArnott closed this as completed Sep 25, 2018
@rgmills
Copy link
Author

rgmills commented Sep 25, 2018

Thanks @frankbuckley and @AArnott . Great surprise to see coming back from vacation!

AArnott pushed a commit that referenced this issue Nov 15, 2023
Bumps [dotnet-coverage](https://github.com/microsoft/codecoverage) from 17.8.6 to 17.9.1.
- [Commits](https://github.com/microsoft/codecoverage/commits)

---
updated-dependencies:
- dependency-name: dotnet-coverage
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants