Search code examples
c#web-servicesdllloadlibrarynanomsg

The type initializer "Class" threw an exception.LoadLibrary failed


I have a service that tries to load a DLL. My service works fine on my development laptop, but when trying it two other laptops I get the following exception:

The type initializer for "NanoProtoApi.Interop" threw an exception. --->System.Exception: LoadLibrary failed: C:\Program Files\Proj\x64\Nanomsg.dll. 

I've checked the dll location and it is definitely there. I have no idea what is going on. Does anyone know what is going on and how to fix this issue?

Here is the exception stack trace:

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()

Solution

  • This usually means that some class in the library three an exception during static construction. Since the exception happened the load fails. In general libraries should take this into account and handle the failures at load time. Since this works for you and there are some traces of network communication in the stack trace I am guessing that there is a problem trying to reach some remote resource. Does this component require connections to other machines? Can those machines be reached from the server?