I've created a unit test (MS Unit Test), which uses COM Dlls for specific operations. If these COM Dlls are registered (via Regsvr32.exe) everything works fine. But if I try to run my test using these COM Dlls as registration free COM Dlls ( side-by-side assembly), the used COM Dlls can't be found
System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {...} failed due to the following error: 80040154. Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
I've created a manifest file for the test Dll (testProjectAssemblyname.dll.manifest). The manifestfile is embedded. The used COM assemblies are located in the test output path. I'm not quite sure, if this setup is correct.
Switching "AnyCPU" to X86 or x64 builds didn't help.
If I'm running my application by using a manifest file and no registered COM Dlls, everything works fine.
Any ideas?
I got a solution -> http://blog.functionalfun.net/2012/09/a-quick-guide-to-registration-free-com.html#:~:text=If%20you%20have%20a%20Unit%20Test%20which%20tries%20to%20create
[...]unit tests are actually being run in a different process (for example, the Resharper.TaskRunner), and the manifest file which you so carefully crafted for your exe is being ignored. Only the manifest on the entry executable is taken into account, and since that’s a generic unit test runner it says nothing about your COM dependencies.
But there’s a workaround. Win32 has some APIs –the Activation Context APIs- which allow you to manually load up a manifest for each thread which needs to create COM components.
This code might also help -> https://gist.github.com/LevYas/7275c6f4e402b99a7512547b98b33632