# CLR hosting from C++: loading an assembly in a specific folder, not the one with the application

• ### Question

• The context:

• the R statistical software is the main application
• an R package loads a DLL written in C/C++, that uses the CLR hosting interfaces.
• I'd like an assembly (C#) to be loaded by that native DLL from a specific folder, using one of the AppDomain.Load method.

So far I've had to put this CLR assembly along the app R.exe for things to work, and using the _AppDomain.Load_2 method in the C++ layer.

This is not an acceptable long term solution, but I find the CLR hosting interface incredibly recalcitrant to loading elsewhere than the location of the main application executable.

Any advice is welcome. For information only, below is my last resort attempt at overcoming the restriction (using some file I/O code poached from another forum).

Regards

std::streampos fileSize = 0;
fileSize = inputFile.tellg();
inputFile.seekg( 0, std::ios::end );
fileSize = inputFile.tellg() - fileSize;
SAFEARRAYBOUND arrayBounds[1] = { {fileSize, 0}};
LPSAFEARRAY safeArray = SafeArrayCreate(VT_I1, 1, arrayBounds);
SafeArrayLock(safeArray);
char* pData = reinterpret_cast<char*>(safeArray->pvData);

inputFile.seekg(0, std::ios::beg);
inputFile.close();