I've seen couple of similar questions but none resolved my problem. The scenario is - i have couple of DLLs in external storage, i need to get the info about them(Assembly version and AssemblyInformationalVersion to be specific). I started with following code:
List<byte[]> assemblies = _client.DownloadAllAssemblies();
foreach(var assemblyBytes in assemblies)
{
var assembly = Assembly.ReflectionOnlyLoad(assemblyBytes);
var assemblyName = assembly.GetName();
... // read version from assembly name
}
Above code works only one time. If i click a button to refresh the view - it throws exception saying that assembly is already loaded and can't reload it. Then i read that i should create temporary domain and load assemblies into it so i can unload the AppDomain after I'm done. I tried following code:
List<byte[]> assemblies = _client.DownloadAllAssemblies();
var tempDomain = AppDomain.Create("TemporaryDomain");
foreach(var assemblyBytes in assemblies)
{
var assembly = tempDomain.Load(assemblyBytes);
var assemblyName = assembly.GetName();
... // read version from assembly name
}
AppDomain.Unload(tempDomain);
Above code throws FileNotFound exception saying "Cannot load file or assembly ..."
I understand why it is happening but i have no idea how to workaround this. The task seems very trivial:
- Load file,
- Read its version,
- Forget about it.
Nothing complicated in above logic. Seems like overcomplicated by runtime requirements. Does anyone know how can i make it work ?