I'm currently experimenting with hosting .NET CoreCLR in a C++ application to basically implement some kind of plugin system.
I used the corerun source code as a base to get started and to explore how to build a native host other tutorials/documentation generally failed in one way or another.
Finally I got it to work, I could initialize the runtime, create an AppDomain and execute a .NET Core assembly.
The next step for me was to run multiple assemblies, so I just created a second test assembly and tried to execute it the same way as the first one.
In fact my application does the following:
Initialize Runtime -> Create AppDomain1 -> Execute Assembly 1 -> Unload AppDomain 1
-> Create AppDomain2 -> Execute Assembly 2 -> Unload AppDomain2
Unfortunately I wasn't able to even create the second AppDomain.
My code for AppDomain creation looks roughly like this:
m_RuntimeHost->CreateAppDomainWithManager
(
L"MyFriendlyName",
appDomainFlags,
nullptr,
nullptr,
sizeof(propertyKeys) / sizeof(wchar_t*),
propertyKeys,
propertyValues,
&domainId
);
My appDomainFlags
are the ones from the corerun
code:
APPDOMAIN_ENABLE_PLATFORM_SPECIFIC_APPS |
APPDOMAIN_ENABLE_PINVOKE_AND_CLASSIC_COMINTEROP |
APPDOMAIN_DISABLE_TRANSPARENCY_ENFORCEMENT
I just assume that all properties I pass here are correct as creation of the AppDomain works at least once.
If I try to create the second AppDomain I just get HRESULT 0x80131022 (Invalid operation)
.
I then went on an examined creation of the runtime interface and replaced the original startup flags of the runtime from:
STARTUP_FLAGS::STARTUP_LOADER_OPTIMIZATION_SINGLE_DOMAIN | STARTUP_FLAGS::STARTUP_SINGLE_APPDOMAIN | STARTUP_FLAGS::STARTUP_CONCURRENT_GC
to:
STARTUP_SERVER_GC | STARTUP_LOADER_OPTIMIZATION_MULTI_DOMAIN | STARTUP_LOADER_OPTIMIZATION_MULTI_DOMAIN_HOST
This was just a guessing game as I don't yet fully understand what exactly these flags do but it didn't change anything unfortunately.
I don't really know any further but I guess I'm missing something important here.
Documentation and articles about this topic are quite rare so I hope that someone here can help me out or give some hints about what might be wrong.