explicot load into default Appdomain fails RRS feed

  • Question

  • Hello,

    we have an Addin written in C# and use a shim written in C++ to load our addin in another Appdomain.

    Now I want to load three CefSharp Assemblies into the Defaultdomain and since I don't have Access in C# to the Deafualt Domain

    I try this in the shim.

    // m_pCorRuntimeHost is of type ICorRuntimeHost
    CComBSTR szCefSharp[] = {L"CefSharp.Core.dll", L"CefSharp.dll", L"CefSharp.Wpf.dll"};
    TCHAR szDirectory[MAX_PATH + 1];
    // for load of CefSharp
    CComPtr<IUnknown> pDefDomain;
    mscorlib::_AppDomain *m_DefDomain = nullptr;
    mscorlib::_Assembly *pAssembly;
    // Get the location of the hosting shim DLL
    IfFailGo(GetDllDirectory(szDirectory, sizeof(szDirectory) / sizeof(szDirectory[0])));
    // load CefSharp dll into DefaultDomain
    bool success;
    hr = m_pCorRuntimeHost->GetDefaultDomain(&pDefDomain);
    success = SUCCEEDED(hr);
    if (success) {
    	hr = pDefDomain->QueryInterface(__uuidof(m_DefDomain), (LPVOID*)&m_DefDomain);
    	success = SUCCEEDED(hr);
    	if (success) {
    		BSTR friendlyName, Basedir;
    		size_t i = 0;
    		std::string mesg;
    		CComBSTR sfile;
    		do {
    			TCHAR szTemp[MAX_PATH + 1];
    			StringCchCopy(szTemp, sizeof(szTemp) / sizeof(szTemp[0]), szDirectory);
    			if (PathAppend(szTemp, szCefSharp[i++])) {
    				sfile = szTemp;
    				hr = m_DefDomain->Load_2(sfile, &pAssembly);
    				success = SUCCEEDED(hr);
    		} while (i < 3);

    Although sfile has the full path


    I get as result of hr = 0x80131047, which means

    The given Assemblyname or the Codebase is invalid

    Basedir is diffferent from L"D:\\arbeit64\\Projekte\\palo\\palo_designer\\XlAddin\\bin\\Debug\\".

    If I jusf use L"CefSharp.Core.dll" I get FILE_NOT_FOUND.

    Is there a way to get it working ?


      Hendrik Schmieder

    Thursday, October 6, 2016 2:52 PM


All replies

  • Hi h_schmieder,

    If you want to interop c# DLL, it seems that we need to use COM interop.

    There are basically four methods to call .NET assembly from native VC++ code. Microsoft All-In-One Code Framework has working examples that demonstrate the methods.

    1. Native VC++ module calls CLR Hosting APIs to host CLR, load and call the .NET assembly. (All-In-One Code Framework Sample Code: CppHostCLR)

    2. If the .NET assembly can be exposed as a COM component, native VC++ module can call into the .NET assembly through .NET – COM interop. (All-In-One Code Framework Sample Code: CppCOMClient)

    3. Reverse PInvoke: the managed code call native passing a delegate the native code can call back. (All-In-One Code Framework Sample Code: CSPInvokeDll)

    4. If the module containing native VC++ code is allowed to enable CLR, the native VC++ code can call .NET assembly directly through the “It Just Works”, or “IJW”, mechanism. (All-In-One Code Framework Sample Code: CppCLIWrapLib)

    Best Regards,

    Cole Wu

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Sunday, October 9, 2016 2:16 PM
  • Sorry for the delay.

    I use already 1), but the Problem is that the load_2 method expect the name without path and Extension.

    Fortunatly I found a link


    which helped me.

    • Marked as answer by h_schmieder Friday, October 14, 2016 9:58 AM
    Friday, October 14, 2016 9:58 AM