简体   繁体   中英

IHostAssemblyStore::ProvideAssembly - Implementation for assemblies from folders

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?

SHCreateStreamOnFile will load the assembly from disc into an IStream, eg:

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 eg "processorarchitecture=amd64" at the end the runtimeHost->Start() call will fail.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM