C# 类型初始值设定项";“类”;引发异常。LoadLibrary失败

C# 类型初始值设定项";“类”;引发异常。LoadLibrary失败,c#,web-services,dll,loadlibrary,nanomsg,C#,Web Services,Dll,Loadlibrary,Nanomsg,我有一个尝试加载DLL的服务。我的服务在我的开发笔记本电脑上运行良好,但在另外两台笔记本电脑上试用时,我得到以下例外情况: The type initializer for "NanoProtoApi.Interop" threw an exception. --->System.Exception: LoadLibrary failed: C:\Program Files\Proj\x64\Nanomsg.dll. 我已经检查了dll的位置,它肯定在那里。我不知道发生了什么事。是否有

我有一个尝试加载DLL的服务。我的服务在我的开发笔记本电脑上运行良好,但在另外两台笔记本电脑上试用时,我得到以下例外情况:

The type initializer for "NanoProtoApi.Interop" threw an exception. --->System.Exception: LoadLibrary failed: C:\Program Files\Proj\x64\Nanomsg.dll. 
我已经检查了dll的位置,它肯定在那里。我不知道发生了什么事。是否有人知道发生了什么以及如何解决此问题

以下是异常堆栈跟踪:

System.TypeInitializationException: The type initializer for 'NanoProtoApi.Interop' threw an exception. ---> System.Exception: LoadLibrary failed: C:\Program Files\Proj\x64\Nanomsg.dll
   at NanoProtoApi.NanomsgLibraryLoader.LoadWindowsLibrary(String libName, SymbolLookupDelegate& symbolLookup)
   at NanoProtoApi.Interop..cctor()
   --- End of inner exception stack trace ---
   at NanoProtoApi.NanomsgSocketBase..ctor(Domain domain, Protocol protocol)
   at NanoProtoApi.Protocols.SubscribeSocket..ctor()
   at MK18.ATR.GATR.GatrProcessingClient.<>c.<runDetectReportFilteredTask>b__26_0() in C:\Users\user\Documents\MK 18\src\coin\mk18atr\project\Utilities\GatrProcessingClient.cs:line 238
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MK18.ATR.GATR.GatrProcessingClient.<SubscribeToDetectReportFiltered>d__25.MoveNext() in C:\Users\user\Documents\MK 18\src\coin\mk18atr\project\Utilities\GatrProcessingClient.cs:line 219
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_1(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
System.TypeInitializationException:“NanoProtoApi.Interop”的类型初始值设定项引发异常。-->系统.异常:LoadLibrary失败:C:\Program Files\Proj\x64\Nanomsg.dll
在NanoProtoApi.NanomsgLibraryLoader.LoadWindowsLibrary(字符串libName、SymbolLookupDelegate和symbolLookup)
在NanoProtoApi.Interop..cctor()上
---内部异常堆栈跟踪的结束---
位于NanoProtoApi.NanomsgSocketBase..ctor(域,协议协议)
在NanoProtoApi.Protocols.SubscribeSocket..ctor()上
在c:\Users\user\Documents\MK 18\src\coin\mk18atr\project\Utilities\GatrProcessingClient.c.b_u26_0()中的MK18.ATR.GATR.GatrProcessingClient.c中:第238行
在System.Threading.Tasks.Task.Execute()中
---来自引发异常的上一个位置的堆栈结束跟踪---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中
在C:\Users\user\Documents\MK 18\src\coin\mk18atr\project\Utilities\GatrProcessingClient.cs中的MK18.ATR.GATR.GatrProcessingClient.d_u25.MoveNext()处:第219行
---来自引发异常的上一个位置的堆栈结束跟踪---
在System.Runtime.CompilerServices.AsyncMethodBuilderCore.c.b_u6_u1(对象状态)
位于System.Threading.ExecutionContext.RunInternal(ExecutionContext ExecutionContext、ContextCallback回调、对象状态、布尔值preserveSyncCtx)
在System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,对象状态,布尔保存SyncCTX)
位于System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()处
在System.Threading.ThreadPoolWorkQueue.Dispatch()中

这通常意味着库中的某些类在静态构造期间会出现异常。由于发生了异常,因此加载失败。一般来说,库应该考虑到这一点,并在加载时处理故障。
由于这对您有效,并且堆栈跟踪中有一些网络通信的跟踪,我猜在尝试访问某些远程资源时会出现问题。此组件是否需要连接到其他机器?服务器是否可以访问这些机器?

当库缺少一个依赖项时,您会得到与库本身缺少一样的异常。检查
Nanomsg.dll
的依赖项。还要检查操作系统的位是否正确(它们都是x64吗?-我注意到dll可能只是x64)。最后,名称NanoProtoApi.Interop意味着还有一个COM库——它是否正确注册了?它似乎没有注册,所以这可能是一些自定义代码。在这种情况下,您可能应该提供您使用的代码(LoadLibrary的PInvoke?)和完整的堆栈跟踪。