If only that was true
I have been experimenting with some alternative's. I get my C++ Bootstrap to load a C# Bootstrap. This C# Bootstrap then creates a new App Domain and loads a new Assembly. Since it's not the default App Domain it can be unloaded. Unfortunately I am having issues calling the method AppDomain::CreateInstanceAndUnwrap which makes use of an Interface to access my new Assembly methods.
All code below has error handling removed and all Absolute referencing removed.
C++ Bootstrapper:
Code:
HRESULT hr = CorBindToRuntimeEx(
NULL,
L"wks",
0,
CLSID_CLRRuntimeHost,
IID_ICLRRuntimeHost,
(PVOID*)&pClrHost);
hr = pClrHost->Start();
//szLibFile points to my C# Bootstrap
DWORD dwRet = 0;
hr = pClrHost->ExecuteInDefaultAppDomain(
szLibFile,
L"Bootstrapper.Entry",
L"Start",
L"TestParam",
&dwRet);
C# Bootstrapper:
Code:
namespace Bootstrapper
{
public class Entry
{
public static int Start(String MyParameter)
{
AppDomainSetup ads = new AppDomainSetup();
ads.ApplicationBase = MyParameter;
ads.DisallowBindingRedirects = false;
ads.DisallowCodeDownload = true;
ads.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
AppDomain MyAppDomain = AppDomain.CreateDomain(string.Format("MyDomain"), null, ads);
IEntry entryInstance = (IEntry)MyAppDomain .CreateInstanceAndUnwrap("BawtLib", "BawtLib.Entry");
entryInstance.Start();
return 0;
}
}
}
C# Bawt Library
Code:
namespace BawtLib
{
[Serializable]
public class Entry : MarshalByRefObject, IEntry
{
public void Start()
{
MessageBox.Show("Bootstrap Loaded Assembly Fine");
}
}
}
C# Shared Interface
Code:
namespace SharedInterface
{
public interface IEntry
{
void Start();
}
}
So my method is:
1. C++ Bootstrapper Loads the CLR into the host process. Then Executes the Entry::Start() Method in the C# Bootstrapper.
2. The C# Boostrapper is suppose to create a new App Domain and create the object located in C# Bawt Library inside that domain. The SharedInterface is an interface to this method.
Unfortunately the line below fails and I am unsure why.
Code:
Entry entryInstance = (IEntry)MyAppDomain .CreateInstanceAndUnwrap("BawtLib", "BawtLib.Entry");