Question

I'm trying to figure out how to load the AppDomainManager assembly in a managed clr hosting scenario from a folder different from the native .exe file.

Has anyone done an IHostAssemblyStore::ProvideAssembly implementation, that will load the AppDomainManager assembly from a folder, and would like to share it?

I'm new to this WinApi/OLE/whatever programming, and I have no idea how to get an IStream* from a file on disk in c++.

Or is there another way load the AppDomainManager for the DefaultDomain from an arbitrary folder?

Was it helpful?

Solution

SHCreateStreamOnFile will load the assembly from disc into an IStream, e.g.:

HRESULT hr = SHCreateStreamOnFile(assemblyPath, STGM_READWRITE, ppStmAssemblyImage);

Pitfall:

The CLR will call your ProvideAssembly implementation several times for one assembly.

Be sure to use the postPolicyIdentity in the AssemblyBindInfo to return the "right" bits at the right call considering the processor architecture:

If your assembly was build "Any CPU" but you return it when the postPolicyIdentity contains e.g. "processorarchitecture=amd64" at the end the runtimeHost->Start() call will fail.

Instead you have to return COR_E_FILENOTFOUND (0x80070002) until the processorarchitecture matches.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top