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

  • 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;
    std::ifstream inputFile("F:\\path\\to\\R\\library\\rClr\\libs\\x64\\ClrFacade.dll", std::ios::binary);
    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.read(pData, fileSize);
    //_AppDomainPtr spDefaultAppDomain 
    hr = spDefaultAppDomain->Load_3(safeArray, &spAssembly);
    // first change EEException * __ptr64, and Unknown error 0x80131533
    
    
    SafeArrayUnlock(safeArray);
    SafeArrayDestroy(safeArray);
    inputFile.close();

    Sunday, November 25, 2012 7:03 AM

Answers