-
Notifications
You must be signed in to change notification settings - Fork 893
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
LibGit2Sharp: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. LibGit2Sharp: Unable to load DLL 'git2-15e1193': The specified module could not be found. #1533
Comments
Good question - LibGit2Sharp relies on libgit2 itself, a native library, which it accesses through PInvoke. I'm not familiar enough to know if you can use pinvoke with Azure Functions, or if we need to adjust the way we load the native libraries so that Azure Functions is successful. |
@ethomson Thanks your for your reply, seems this is a quite new question of LibGit2Sharp. Can you tell me which PInvoke should I use? Can I find it through NuGet? If it's available on NuGet, then I can try to add it to my function app. |
@CalvinFengDatacom You don't have to add anything. The LibGit2Sharp package includes a reference to the LibGit2Sharp.NativeBinaries package, which includes the required native library. There must be something specific to how Azure Functions works that is preventing the native library from being in the expected location when your code runs. |
@bording Thanks, I see when I reload the packages of my Azure function App, LibGit2Sharp.NativeBinaries/1.0.185 has been added automatically. But, I'm happy to try other ways if you guys have some idea. I can just setup a small Function App to try this. |
Are you able to run this locally in Azure Functions Core Tools? Are you set up for a 64 bit Azure Function runtime? https://blogs.msdn.microsoft.com/benjaminperkins/2017/02/09/azure-functions-on-64-bit/ |
@ethomson I have changed for using 64 bit of Azure function runtime, but still got the same result. |
@ethomson I have tried to debug Azure function locally from Visual studio by Attach Debugger. I got the same issue from log console: LibGit2Sharp: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. LibGit2Sharp: Unable to load DLL 'git2-15e1193': The specified module could not be found. Um... Seems I have tried everything already. |
@ethomson @bording Hi guys, any updates of using LibGit2Sharp in Azure function app? I have tried to run azure function app locally following this way https://blogs.msdn.microsoft.com/webdev/2016/12/01/visual-studio-tools-for-azure-functions/ But, I still got the same issue from log console. |
I get the same message when trying to run a .NET Core app (v0.25.0-preview0073) inside a Linux docker container (using Windows 10 Docker for Windows). According to this comment, I expected it works inside a Linux containers. Running an app inside Windows container works ok, but it's not an option for me, because I already use Linux containers for another app (WIndows for Docker can not run both types of containers simultaneously). |
@MikhailTymchukDX please try using a debian based container. If you're using alpine or centos, you will need to provide your own libgit2 binaries. |
@ethomson Thanks for that tip! I changed base image to |
Changing to jessie didn't quite do the trick: I'm still getting the same error with this simple program using LibGit2Sharp;
namespace TestClone
{
class Program
{
static void Main(string[] args) => Repository.Clone("https://github.com/tgstation/tgstation", "tgstation");
}
} Only dep is LibGit2Sharp 0.25.0-preview-0081
Result:
EDIT: Upon further investigation this seems to be unique to the aspnetcore image. dotnet-sdk and aspnetcore-build work fine |
I'm getting the same problem also (in a docker container). Maybe this is naive, but is the issue not just that the libgit2sharp.nativebinaries package ships the file as There's some discussion of these naming issues in dotnet/coreclr#930. (Using |
I actually got the aspnetcore image working by installing these packages:
https://github.com/Cyberboss/MapDiffBot/blob/bcde6d6c150cafede52b419f61ead05896b316ab/MapDiffBot/Dockerfile#L22
…On Thu, Mar 29, 2018, 8:59 PM Matt Johnson ***@***.***> wrote:
I'm getting the same problem also (in a docker container). Maybe this is
naive, but is the issue not just that the libgit2sharp.nativebinaries
package ships the file as git2-version.dll on Windows, and
libgit2-version.so on Linux?
There's some discussion of these naming issues in dotnet/coreclr#930
<https://github.com/dotnet/coreclr/issues/930>.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1533 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHyweofWO6Tv9daDDEZEl9sAymNukD0rks5tjYOEgaJpZM4SBidm>
.
|
@mj1856 That pattern is the one that is already accounted for via There are two things that could be causing the problem:
|
Ok, I got it working with Jessie. I'm not using asp.net core, just the dotnet base images. The Thanks. |
The method I went through to find what was missing was installing `ld` on
the image and then running it on libgit2-xxxxxxx.so to see what couldn't be
found.
On Apr 2, 2018 1:28 PM, "Matt Johnson" <[email protected]> wrote:
Ok, I got it working with Jessie. I'm not using asp.net core, just the
dotnet base images. microsoft/dotnet:2.0-runtime-jessie and
microsoft/dotnet:2.0-sdk-jessie. Of the dependencies listed in @Cyberboss
<https://github.com/Cyberboss>'s link, the only one I needed to install was
libcurl3-gnutls. I'm guessing this is because I was cloning an https repo.
The -stretch images did not work, so I'm wondering what else needs to be
installed there. Also, I'd prefer to use openssl instead of gnutls, but I'm
not sure how to do that. Anyone know?
Thanks.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1533 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHywesxYAtIzolXpIVowkpWt-cxsY6LMks5tkl_HgaJpZM4SBidm>
.
|
did anyone managed to get this working inside an azure function? |
I was having this same issue on a microsoft/aspnetcore:2.0 Docker image.
Then I pasted this code right below the FROM line...
Then it worked. |
I don't yet have a full understanding of Azure Functions, but: #1574 (comment) indicates that this is indeed possible:
|
There might be some changes in the native dependencies in 2.1 docker images. The above method worked in 2.0 jessie images, but does not work on 2.1 because only |
#1582 should hopefully be addressing this. |
I have the same issue when trying to run LibGit2Sharp in PowerShell Core on macOS: > [LibGit2Sharp.Repository]::new($PWD)
Exception calling ".ctor" with "1" argument(s): "The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception."
At line:1 char:1
+ [LibGit2Sharp.Repository]::new($PWD)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : TypeInitializationException LibGit2Sharp v0.25.2 |
@felixfbecker That doesn't sound like it has anything to do with this issue, which is regarding Azure Functions. |
I figured I would comment here since it's the same error message and people above also said they are having the same issue on Linux and in Linux Docker containers. |
Yeah, this thread has become very messy with similar problems (can't load the native libraries) but very different root causes / platforms. A new issue would be helpful. |
I have a similar issue building *.msi Windows Installer file. When I include following files to the output folder, it works. |
I got similar error when running under target framework of 4.6.1. When I changed target framework to 4.6.2 the problem solved. |
Found temporary solution for docker:
|
An update for those trying to get libgit2sharp to work in Azure Functions. (This is just my own experience. YMMV.) If you publish your project with default "portable" (i.e. "any" platform), then libgit2sharp will use the the native libgit2 library from the On some Linux environments, libssl 1.0 is pre-installed. However, Linux-based Azure Functions currently uses Debian 9 ("stretch" ) or Debian 10 ("buster") as its runtime. Debian 9 has a libssl 1.0 library available, but not pre-installed. Debian 10 does not have a libssl 1.0 library at all. Thankfully, libgit2sharp has a Debian 9 native libgit2 library in its runtimes folder, which was built against libssl 1.1. Therefore, all you need to do to work around this issue is publish using the Debian 9 runtime identifier, which is If you publish on the command line, add If you publish from Visual Studio, first create a publishing profile (or edit your existing one), selecting If you publish from VSCode, edit the |
I'm using Azure Function App to create a app for updating Excel file to our ASP.Net Web Api project, which is hosting in Azure, and we are using Git to control the version of files.
Now, I'm having an issue of using LibGit2Sharp. I'd like to use Commands.Checkout() command to switch between branches. However, I got this issue:
LibGit2Sharp: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. LibGit2Sharp: Unable to load DLL 'git2-15e1193': The specified module could not be found.
I'm using the latest version of LibGit2Sharp version 0.24.0, and I see it depends on LibGit2Sharp.NativeBinaries": "[1.0.185]"
Does anyone who has any idea how to solve this issue on Function App?
Thanks
The text was updated successfully, but these errors were encountered: