2

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()
Roka545
  • 3,404
  • 20
  • 62
  • 106
  • 2
    When a library has one of its dependencies missing you get the same exception as if the library itself is missing. Check the dependencies of `Nanomsg.dll`. Also check the OS bit-ness (are they all x64? - I notice the dll is probably x64 only). Finally, the name NanoProtoApi.Interop implies there's a COM library as well - is it properly registered? – P. Kouvarakis Mar 30 '17 at 20:51
  • 1
    It doesn't seem to be [TypeLoadException](http://stackoverflow.com/questions/7487544/how-can-i-troubleshoot-system-typeloadexception), so that is probably some custom code. In such a case you should probably provide the code you use (PInvoke of LoadLibrary?) and full stack trace. – Eugene Podskal Mar 30 '17 at 20:51
  • I've added the stack trace to the original post. – Roka545 Mar 30 '17 at 20:56

1 Answers1

1

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?

Mike
  • 3,462
  • 22
  • 25