I understand that a loaded assembly cannot be unloaded directly, so I created a temporary domain and a loaded assembly, but I had an error creating shadow files.
The code I wrote is as follows:
[LoaderOptimization(LoaderOptimization.MultiDomainHost)]
[STAThread]
static void Main(string[] args)
{
string startupPath = @"D:\Temp\MyLib\bin\Debug";
string cachePath = Path.Combine(startupPath, "__cache");
string assembly = Path.Combine(startupPath, "MyLib.dll");
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationName = "MyLIb";
setup.ShadowCopyFiles = "true";
setup.CachePath = cachePath;
AppDomain domain = AppDomain.CreateDomain("MyLIb", AppDomain.CurrentDomain.Evidence, setup);
var np = FindFileInPath("MyLib.dll", cachePath);
var ass = Assembly.LoadFile(np);
var types = ass.GetTypes();
AppDomain.Unload(domain);
}
I had an error while searching for a file on the path "could not find part of the path" D: \ Temp \ MyLib \ bin \ Debug__cache. "
public static string FindFileInPath(string filename, string path)
{
filename = filename.ToLower();
foreach (var fullFile in Directory.GetFiles(path))
{
var file = Path.GetFileName(fullFile).ToLower();
if (file == filename)
return fullFile;
}
foreach (var dir in Directory.GetDirectories(path))
{
var file = FindFileInPath(filename, dir);
if (!string.IsNullOrEmpty(file))
return file;
}
return null;
}
}
Can anyone help me get rid of this problem.
Thanks in advance. Joon
source
share