【问题标题】:The type initializer "Class" threw an exception.LoadLibrary failed类型初始化程序“Class”引发了异常。LoadLibrary 失败
【发布时间】:2017-03-30 20:44:37
【问题描述】:

我有一个尝试加载 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()

【问题讨论】:

  • 当一个库缺少其中一个依赖项时,您会得到与缺少库本身相同的异常。检查Nanomsg.dll 的依赖关系。还要检查操作系统的位数(它们都是 x64 的吗?-我注意到 dll 可能只是 x64)。最后,NanoProtoApi.Interop 这个名字意味着还有一个 COM 库——它是否正确注册?
  • 好像不是TypeLoadException,所以这可能是一些自定义代码。在这种情况下,您可能应该提供您使用的代码(LoadLibrary 的 PInvoke?)和完整的堆栈跟踪。
  • 我已将堆栈跟踪添加到原始帖子中。

标签: c# web-services dll loadlibrary nanomsg


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-15
    • 2021-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-28
    • 1970-01-01
    相关资源
    最近更新 更多