Search code examples
c#dllnativemanaged

Debugger hangs when performing a native DLL call from referenced managed Assembly


My C# project is referencing managed dll that has dependencies on a native dll. Therefore, before calling managed dll function I copy native dll to folder: Path.GetDirectoryName(Assembly.GetAssembly(typeof(ManagedDllClass)).Location).

I'm still, however, encountering the problem where while performing a native call my debugger is hanging. What can be the cause of this? What is the preferred way of dealing with the situation where referenced managed dll is depending on a native dll?

Thanks


Solution

  • "Native DLL" is actually misleading in this case.

    .NET can only interface with COM server DLLs using COM Interop. In general, COM DLLs need to be registered with the OS in order to be accessible via .NET - they are not generally xcopy compatible like .NET assemblies.

    If you don't know for sure that the COM server DLL has been registered, use regsvr32.exe to register the DLL again.

    More instructions on how to use regsvr32.exe : How to use the Regsvr32 tool and troubleshoot Regsvr32 error messages