1

I'm attempting to build a C# desktop application on Windows with Xamarin Studio. After importing the LibGit2Sharp package (and consequently the LibGit2Sharp.NativeBinaries package), any attempt to actually use the library results in one of these:

Exception in Gtk# callback delegate
  Note: Applications can use GLib.ExceptionManager.UnhandledException to handle the exception.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.DllNotFoundException: git2-785d8c4
  at (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_config_find_xdg (LibGit2Sharp.Core.Handles.GitBuf)
  at LibGit2Sharp.Core.Proxy.ConvertPath (System.Func`2 pathRetriever) [0x00006] in <filename unknown>:0 
  at LibGit2Sharp.Core.Proxy.git_config_find_xdg () [0x00000] in <filename unknown>:0 
  at LibGit2Sharp.Configuration..ctor (LibGit2Sharp.Repository repository, System.String repositoryConfigurationFileLocation, System.String globalConfigurationFileLocation, System.String xdgConfigurationFileLocation, System.String systemConfigurationFileLocation) [0x00032] in <filename unknown>:0 
  at LibGit2Sharp.Configuration.BuildFrom (System.String repositoryConfigurationFileLocation, System.String globalConfigurationFileLocation, System.String xdgConfigurationFileLocation, System.String systemConfigurationFileLocation) [0x00000] in <filename unknown>:0 
  at LibGit2Sharp.Configuration.BuildFrom (System.String repositoryConfigurationFileLocation, System.String globalConfigurationFileLocation) [0x00000] in <filename unknown>:0 
  at bravura.tools.git.helper.operations.CoreSettings.run () [0x00015] in C:\code\bravura\git-helper\operations\CoreSettings.cs:37 
  at bravura.tools.git.helper.operations.CoreMenu.OnButtonOkReleased (System.Object sender, System.EventArgs e) [0x00020] in C:\code\bravura\git-helper\operations\CoreMenu.cs:43 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in C:\j\workspace\v\repos\mono\mcs\class\corlib\System.Reflection\MonoMethod.cs:295

I've found that manually putting the dll and pdb in the root output directory sorts out the issue, but that doesn't make for a good build process. Really, there should be a way to add the "NativeBinaries*" directory to the load path. I've already attempted to load the library manually, but since it's not .NET, that option just doesn't work.

Am I missing something obvious? Is this a common issue that I'm just blundering around on?

I've already checked the following issues to no avail:

2
  • 1
    If you do not want the git2-785d8c4.dll to be in the same directory as you .exe you will probably have to use SetDllDirectory and specify its location. Commented Mar 7, 2016 at 20:59
  • Couldn't find the namespace for that function, but while searching, I found a fix that seems to work. Commented Mar 7, 2016 at 21:42

1 Answer 1

0

After looking around a bit, and a helpful point in the right direction by Matt Ward, I found a working answer while reading Loading dlls from path specified in SetdllDirectory in c#, or more specifically, this comment.

string newPath = Environment.GetEnvironmentVariable("PATH") +
    ";" + Environment.CurrentDirectory + "\\NativeBinaries\\x86\\";
Environment.SetEnvironmentVariable("PATH", newPath);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.