Why .NET Framework assemblies are not loaded inside same AppDomain of calling module?

30 Views Asked by At

I'm using C++/CLI exe that creates AppDomain and loads another assembly dll of mine, into this AppDomain.

The dll assembly uses .NET APIs that cause .NET assemblies to load. however, it looks like the .NET assemblies (such as Windows.Storage.Search.dll) are not loaded into the AppDomain I created -> I print the domain assemblies, but it's not there, although I can see the .NET dlls loaded in Process Explorer. code below.

Why the dependent .NET assemblies are not loaded into AppDomain of the calling dll assembly?

//create AppDomain and load MyAssembly into it
System::AppDomain^ domain = System::AppDomain::CreateDomain("Domain");
System::Reflection::AssemblyName^ assemblyName = gcnew System::Reflection::AssemblyName();
assemblyName->CodeBase = "C:\\MyAssembly.dll";
System::Reflection::Assembly^ assembly = domain->Load(assemblyName);

//call a method inside the MyAssembly, that uses Storage API
assembly->GetType("MyNS.MyClass")->GetMethod("StorageMethod")->Invoke(nullptr, nullptr);

//view Process Explorer loaded dlls in my process -> I can see Windows.Storage.Search.dll
//print here domain->GetAssemblies() -> Windows.Storage.Search.dll does not appear...

System::AppDomain::Unload(domain);

//view Process Explorer loaded dlls in my process -> I still can see Windows.Storage.Search.dll, although domain is unloaded
0

There are 0 best solutions below