首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在fsharp中使用libgit2sharp

如何在fsharp中使用libgit2sharp
EN

Stack Overflow用户
提问于 2018-06-25 19:41:01
回答 1查看 282关注 0票数 4

这是在带有net471Server 2016上,它的行为应该类似于windows 10

所以我在我的paket.dependencies中通过nuget LibGit2Sharp prerelease下载,它解析为

代码语言:javascript
复制
LibGit2Sharp (0.26.0-preview-0027)
LibGit2Sharp.NativeBinaries (1.0.226) - restriction: >= netstandard2.0

在新的fsi (使用ionide )中,我可以引用LibGit2Sharp.dll并打开LibGit2Sharp名称空间,但实例化存储库会抛出以下错误:

代码语言:javascript
复制
Microsoft (R) F# Interactive version 10.1.0 for F# 4.1

> #r "../../packages/play/LibGit2Sharp/lib/netstandard2.0/LibGit2Sharp.dll";;

--> Referenced 'd:\scripts2dev\libwba\src\play\../../packages/play/LibGit2Sharp/lib/netstandard2.0/LibGit2Sharp.dll' (file may be locked by F# Interactive process)

> open LibGit2Sharp;;
> let  repo = new Repository("path\to\repo.git");;
System.TypeInitializationException: The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'git2-b0d9952': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at LibGit2Sharp.Core.NativeMethods.git_libgit2_init()
   at LibGit2Sharp.Core.NativeMethods.InitializeNativeLibrary()
   at LibGit2Sharp.Core.NativeMethods..cctor()
   --- End of inner exception stack trace ---
   at LibGit2Sharp.Core.NativeMethods.git_repository_open(git_repository*& repository, FilePath path)
   at LibGit2Sharp.Core.Proxy.git_repository_open(String path)
   at LibGit2Sharp.Repository..ctor(String path, RepositoryOptions options, RepositoryRequiredParameter requiredParameter)
   at <StartupCode$FSI_0003>.$FSI_0003.main@() in d:\scripts2dev\libwba\src\play\LibGit2Sharp.fsx:line 4
Stopped due to error

而且我不能引用来自LibGit2Sharp.NativeBinariesdll,因为它抛出

代码语言:javascript
复制
> #r @"../..\packages\play\LibGit2Sharp.NativeBinaries\runtimes\win-x64\native\git2-b0d9952.dll";;

LibGit2Sharp.fsx(7,1): error FS0229: Error opening binary file 'd:\scripts2dev\libwba\src\play\../..\packages\play\LibGit2Sharp.NativeBinaries\runtimes\win-x64\native\git2-b0d9952.dll': d:\scripts2dev\libwba\packages\play\LibGit2Sharp.NativeBinaries\runtimes\win-x64\native\git2-b0d9952.dll: bad cli header, rva 0

LibGit2Sharp.fsx(7,1): error FS3160: Problem reading assembly 'd:\scripts2dev\libwba\src\play\../..\packages\play\LibGit2Sharp.NativeBinaries\runtimes\win-x64\native\git2-b0d9952.dll': Processing of a script fragment has stopped because an exception has been raised

我遗漏了什么?如何使用已编译的库?

EN

回答 1

Stack Overflow用户

发布于 2021-06-09 00:17:10

如果你通过kernel32的LoadLibrary加载原生动态链接库,它应该可以工作。这有帮助吗?

另请参阅https://christoph.ruegg.name/blog/loading-native-dlls-in-fsharp-interactive.html

代码语言:javascript
复制
[<DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)>]
extern IntPtr LoadLibrary(string lpFileName);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51022648

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档