AxoCover
AxoCover copied to clipboard
The C++ module failed to load while attempting to initialize the default appdomain.
Hi,
I have a problem with running test with mixed assemblies native and managed.
In Test Explorer tab from Visual Studio, There is no problem.
If I try to run test in AxoCover tab from Visual Studio, test fails due to exception System.TypeInitializationException: The type initializer for '<Module>' threw an exception, with inner exception "The C++ module failed to load while attempting to initialize the default appdomain."
What is the difference when it runs from testhost.exe and from AxoCover.Host-x64.exe?
Thanks
Could it be that you C++ code is x86? In which case you would need to change the platform in AxoCover settings.
It could be also caused by the fact that the tests in AxoCover do not execute in the default appdomain.
My C++/CLI dlls is targeted at x64 and platform in AxoCover's Test settings is also x64.
At first i face the problem, test was also failed in Test Explorer tab.
After searching, i found out this document.
https://developercommunity.visualstudio.com/content/problem/169359/ccli-dll-is-initialized-in-wrong-appdomain.html
So i modified the code that having static field with gcroot in a C++/CLI dlls, then test was passed.
But in AxoCover tab, after C++/CLI dll loaded, finding managed dll only in a directory that AxoCover.Host-x64.exe exists, not in my test dlls exist.
Now, i'm making a batch file that using OpenCover and ReportGenerator to confirm the code coverage and it has no problem.
Any help?
thanks in advance.
So if understand correctly now the problem is with AxoCover not finding the DLLs if they are not in the runner's directory? That could happen if they reference other native DLLs, since the native DLL search paths are different. I could set the PATH environment var for the runner process to include the test DLL's directory, that should fix finding the native DLLs.
To validate the above theory you could try to set the PATH environment variable on your machine to include the directory of your DLL, and restart Visual Studio and try if it works with AoxCover. If it does please tell me and I will make the change, if not we look for another solution.
I did what you said, but nothing's changed. So it seems to be an issue not related to PATH environment var. When C++/CLI DLL loaded, maybe new AppDomain is being created for some reason. And i think this is probably a Visual Studio bug. I will try to find out more for myself.
Thank you anyway.
Could you create a minimalistic sample project for me, which I could check to reproduce the error you encounter?
I never used AxoCover with mixed mode DLLs so far, so this is an uncharted territory for the engine.
(AxoCover runs tests in separate AppDomain, if this is the issue, I could try to add the setting - this might be simple or not so simple depending on the test framework. Which test framework do you use?)
This is a minimalistic sample project that i first encounter. TestDemo.zip
Thanks, I will take a look over the weekend.
I looked at your example, if I declare your variable like this:
static ManagedClass^ g_managed = gcnew ManagedClass(); in your class in the header, then it works properly.
For the tests to run in VS you need a runsettings file to be specified for running in x64 mode, I used this: