Result StackTrace:
at LibGit2Sharp.Core.Platform.get_OperatingSystem()
at LibGit2Sharp.Core.NativeMethods..cctor()
--- End of inner exception stack trace ---
at LibGit2Sharp.Core.NativeMethods.git_repository_init_ext(git_repository*& repository, FilePath path, GitRepositoryInitOptions options)
at LibGit2Sharp.Core.Proxy.git_repository_init_ext(FilePath workdirPath, FilePath gitdirPath, Boolean isBare)
at LibGit2Sharp.Repository.Init(String path, Boolean isBare)
at Microsoft.Windows.Engineering.GitTrain.TestHelpers.SourceControl.TestRepositoryContext..ctor(String testContainerPath) in F:\repos\scm.git.train\Tests\Ms.Wdg.Es.GitTrain.TestHelpers\SourceControl\TestRepositoryContext.cs:line 49
at Ms.Wdg.Es.GitTrain.Core.Tests.GitSourceControlServiceTests.GitSourceControlServiceTestsContext..ctor() in F:\repos\scm.git.train\Tests\Ms.Wdg.Es.GitTrain.Core.Tests\GitSourceControlServiceTests.cs:line 1008
at Ms.Wdg.Es.GitTrain.Core.Tests.GitSourceControlServiceTests.GenerateMoveCommitFromSpecificationCanHandleDirectoriesThatAreSubstringsOfOtherDirectories() in F:\repos\scm.git.train\Tests\Ms.Wdg.Es.GitTrain.Core.Tests\GitSourceControlServiceTests.cs:line 891
Result Message:
Test method Ms.Wdg.Es.GitTrain.Core.Tests.GitSourceControlServiceTests.GenerateMoveCommitFromSpecificationCanHandleDirectoriesThatAreSubstringsOfOtherDirectories threw exception:
System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
@halfpeaw What is the target framework for the project where you're seeing this? Can you provide a project that reproduces the error?
Target framework is .NET 4.6.1. The project failing is internal to Microsoft, but I can get it to repro on my small project that references the libgit2sharp project directly.
All I'm doing is running this command: Repository.Init("testthing", isBare: true);
My mistake the failure happens in the same spot when I run libgit2sharp directly in my smaller repro, but the error is this: Inner Exception 1:
DllNotFoundException: Unable to load DLL 'git2-15e1193': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Which may be an issue with with how I'm building libgit2sharp...
Which may be an issue with with how I'm building libgit2sharp...
Are you using the NuGet packages, or are you using an assembly you built yourself?
Was using nuget package in the "big real project", but was getting the original failure. I am building it directly now to see if I can figure out whats wrong by using the debugger. Got the different error when trying to build it in a smaller custom project that also built LibGit2Sharp directly.
My guess is something to do with the build environment of the "big real project" since running the exact same built binaries results in a different error in my smaller custom project.
Additionally dumped Environment.version in my Big Project and it resulted in 4.0.30319.42000, which should be 4.6/4.7
What OS are you on? Do you have .NET Framework 4.7.1 installed? If so, you're probably hitting https://github.com/dotnet/standard/issues/567
You should be able to clear that up by fixing the binding redirect, or targeting net47 or net471 instead.
My highest version is 4.6.2. I'm running Server 2016. I'm fairly convinced it has something to do with the project configuration it self, since my significantly simpler project doesn't repro the issue with the nuget package, which rules out the OS itself. This issue didn't exists in the .33 preview.
@halfpeaw The difference between preview 73 and preview 33 is that preview 73 now only ships a netstandard2.0 assembly, so you could definitely be hitting the problem now and not on the previous preview release. I suggest checking the binding redirects as mentioned in the issue I linked.
I've verified that the latest preview package works on a new net461 project, so if you can provide a repro that demonstrates the problem that would be helpful.
Ok I'll see if I can try the binding redirects, additionally I'll see if I can get the repro to happen on a smaller scale.
Would you expect the assemblybindings to reference the System.Runtime.InteropServices.RuntimeInformation assembly?
This solution contains several projects but the unit test one that is failing has bindings that look like this:
`
<dependentAssembly>
<assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.13.9.1126" newVersion="3.13.9.1126" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.ServiceBus" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IdentityModel.Tokens.Jwt" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.1.3.0" newVersion="5.1.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.IdentityModel.Clients.ActiveDirectory.Platform" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.13.9.1126" newVersion="3.13.9.1126" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.SqlServer.TransactSql.ScriptDom" publicKeyToken="89845dcd8080cc91" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-14.0.0.0" newVersion="14.0.0.0" />
</dependentAssembly>
</assemblyBinding>
`
You might actually be missing some that you need. Can you try removing all of that from your app.config and have it regenerate the binding redirects automatically?
In a fresh console app targeting net461 with no manually defined binding redirects, the resulting bin output includes an exe.config file that has a bunch of redirects, including one for System.Runtime.InteropServices.RuntimeInformation.
I went through and manually added the following to all the app.config files with a dependency on libgit2sharp. Not sure why nuget didn't auto update the app.config. Fortunately I was able to move past that particular error. Thank you for your help!
<dependentAssembly>
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
I went through and manually added the following to all the app.config files with a dependency on libgit2sharp.
You should consider removing the binding redirects from your app.configs altogether and let them be generated during build instead. That way you won't find yourself in a situation like that in the future!
Is anyone exploring a permanent fix for this issue? I ran into it after creating a brand new project. The binding redirects were not generated automatically.
Most helpful comment
I went through and manually added the following to all the app.config files with a dependency on libgit2sharp. Not sure why nuget didn't auto update the app.config. Fortunately I was able to move past that particular error. Thank you for your help!