如何在 Service Fabric 上导入本机 DLL?

How to import native DLL on Service Fabric?

我确实想将本机 DLL 导入到 Microsoft Service Fabric 服务中。这可能吗?如果是这样,我该如何实现?我想我被困在如何告诉部署也部署本机 DLL 以便能够稍后在运行时导入它。目前我收到运行时错误,找不到 dll。当整个应用程序部署到服务结构集群时,我想我还需要以某种方式在那里获取所需的本机 DLL。

非常感谢任何帮助!提前致谢!

此致

马里奥

编辑: 抱歉,我可能对我的方法和错误知之甚少。我尝试像这样在我的 C# 服务中导入本机 DLL:

[DllImport("Plugin.dll", 
    EntryPoint = "DoSomeStuff",
    CallingConvention = CallingConvention.Cdecl)]
public static extern int DoSomeStuff();

然后在StatelessService的继承函数RunAsync中调用引入的函数:

protected override async Task RunAsync(CancellationToken cancellationToken)
{
    DoSomeStuff();
}

天真地,我的第一种方法是简单地将所需的 Plugin.dll 文件放入其他可执行文件所在的 bin 文件夹中。但是它们要么没有被移动到集群中,要么无法被运行时找到。

在运行时我确实得到以下异常:

System.DllNotFoundException: Die DLL \"Plugin.dll\": Das angegebene Modul wurde nicht gefunden. (Ausnahme von HRESULT: 0x8007007E) kann nicht geladen werden.
bei DoSomeStuff()
bei Application.<RunAsync>d__2.MoveNext() in C:\SolutionPath\ProjectPath\Application.cs:Zeile 45.
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
bei Microsoft.ServiceFabric.Services.Runtime.StatefulServiceReplicaAdapter.<ExecuteRunAsync>d__e.MoveNext()"

抱歉德语错误信息(原创),我尝试翻译:

System.DllNotFoundException: The DLL \"Plugin.dll\": The specified Module was not found. (Exception of HRESULT: 0x8007007E) cannot be loaded.
at DoSomeStuff()
at Application.<RunAsync>d__2.MoveNext() in C:\SolutionPath\ProjectPath\Application.cs:Zeile 45.
--- End of stack trace of the exception origin, where the exception was raised ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.ServiceFabric.Services.Runtime.StatefulServiceReplicaAdapter.<ExecuteRunAsync>d__e.MoveNext()"

在这里查看我的回复:。您可以通过以下两种方式之一完成此操作:将本机 DLL 文件指定为服务项目的内容文件,或者在应用程序项目的 post-Package MSBuild 步骤中手动将文件复制到服务包。