-
Notifications
You must be signed in to change notification settings - Fork 873
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
The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. #446
Comments
This reminds me of issue #288. The LibGit2Sharp assembly expects to find next to it a directory structure as follows
|
I have used the NuGet package. I was able to get further details about the error: Have check and the files are in the folders like the. |
I cannot reproduce this. Can you please share a .zip file of a stripped down version of your project so that I can investigate? |
You can download the project from the link bellow This is a visual studio addin, when you run it a new instance of the visual studio will open and you should go to Tools -> BindTuning to open the form. |
Hmmm. Sadly I'm not a VSIX expert. 😿 However, you may get some inspiration from @xpaulbettsx's SaveAllTheTime Visual Studio extension which also relies on LibGit2Sharp. More specifically, it looks like the .csproj file specifically includes as content the .dll and .pdb files and relies on the IncludeInVSIX directive. |
Yes, that's the trick:
|
@xpaulbettsx Thanks for giving a hand. You ROCK, mate! @joaoferreira Closing this now. Feel free to add a comment if the problem isn't fixed by @xpaulbettsx's guidance |
Exactly what I was looking for for GitDiffMargin. Thanks @xpaulbettsx |
I have the same problem but in mono. What file I have to include? |
@aloon You most likely need to add a DLLMap section to your app config, to map git2-90befde to your system libgit2 (or whatever libgit2 you intend to use): http://www.mono-project.com/Interop_with_Native_Libraries |
@paulcbetts I have not tried yet but it sure is the solution for me. thank you very much |
@aloon In order to avoid side effects, I suggest you to always rely on the exact libgit2 version that is pointed at by the submodule. Take a look at build.libgit2sharp.sh to get a quick glimpse at the recommended CMake options to build the native binary. Then, provided the libgit2 path is added to [DY]LD_LIBRARY_PATH, LibGit2Sharp should be able to directly bind to it. As far as I know, we've been able to work like this without relying on the If your use case requires a /cc @Therzok |
In case anyone comes across this again. Here is how I solved the issue of native binaries not being copied across. Have a project property file that references LibGit2Sharp <?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<None Include="path-to\git2-e0902fb.dll">
<Link>NativeBinaries\amd64\git2-e0902fb.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="path-to\git2-e0902fb.pdb">
<Link>NativeBinaries\amd64\git2-e0902fb.pdb</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="path-to\x86\git2-e0902fb.dll">
<Link>NativeBinaries\x86\git2-e0902fb.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="path-to\x86\git2-e0902fb.pdb">
<Link>NativeBinaries\x86\git2-e0902fb.pdb</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project> Reference it in your library. <Import Project="LibGit2Sharp.props" Condition="Exists('LibGit2Sharp.props')" /> In your run project (the main project). Add the following. <ItemGroup>
<Content Include="$(OutputPath)\NativeBinaries\**\*.dll">
<Link>NativeBinaries\%(RecursiveDir)%(Filename)%(Extension)</Link>
<Visible>false</Visible>
<PublishState>Include</PublishState>
</Content>
</ItemGroup> |
New user - I created a simple console application in VS2015, installed LibGit2Sharp 0.22.0 via Nuget, and got the same error as above (The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception) when running the following hello world example: using System;
namespace GitTest
{
class Program
{
static void Main(string[] args)
{
LibGit2Sharp.Repository.Clone(@"https://github.com/libgit2/libgit2sharp.git", @"H:\");
}
}
} I wonder why a basic Nuget Install doesn't work for me for this package? @nulltoken? None of the above solutions work... |
@chrisRedwine Does your project also include the LibGit2Sharp.NativeBinaries package? |
@bording Yes, installing LibGit2Sharp v0.22.0 also installed LibGit2Sharp.NativeBinaries v1.0.129 for me. |
@chrisRedwine Do you have your example online anywhere that I could see if I can repro the problem locally? |
@bording Not sure if this will work for you, but I added it as a dummy repo to my profile (https://github.com/chrisRedwine/GitTest), with no gitignore. Third commit is before adding LibGit2Sharp, fourth commit is after. Thanks! |
@chrisRedwine Everything looks fine with that project, and once I adjusted for the non-existent H: drive on my machine, it runs without errors. |
@bording Interesting. Well, that's helpful info - thanks so much for looking into it. |
I'm build a Windows Form application and each time I try to make a clone of a repository I get this error The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. without any further detail.
Anyone knows what could be causing this, I'm getting crazy trying to figure it out.
The text was updated successfully, but these errors were encountered: