Answer to my question my already be on stackoverflow however, I just can't find the right one/not get it to work.
What I'm trying to do is, load the .dll to my Windows Form, use reflection to retrieve method/class names. I have got it to work using Assembly.LoadFrom
however it's doing exactly what I wanted as this locks the .dll file.
I have read around and found out that AppDomain
can do the trick however, I just can't get it to do the trick.
Below is the code I have tried however, in CreateInstanceFromAndUnwrap
, I don't know which typeName
it's looking for.
var executableFilePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
AppDomain domain = AppDomain.CreateDomain(
DllPath,
null,
new AppDomainSetup
{
ApplicationBase = Path.GetPathRoot(executableFilePath),
PrivateBinPathProbe = string.Empty,
PrivateBinPath = string.Join(";", DllPath, executableFilePath),
ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile,
});
var temp = domain.CreateInstanceFromAndUnwrap(DllPath, typeof(????).FullName, false,
BindingFlags.Default, null, null, null, null);
The .dll I will load at runtime will not be referenced into my Windows Form application.