If I use reflection to retrieve an assembly, it will seek out the assembly and then cache it. I can tell this because, if it fails to find the assembly, it won’t find it even after I add it to the correct location. If it finds the assembly and I remove it, it still uses the assembly it found and cached.
I know I’m not the only one to have this issue: Clear .Net Reflection cache
The code I’m using to get the assembly is the following – and I make this call every time (not caching myself):
// Try to get the assembly referenced.
Assembly reflectedAssembly;
try
{
reflectedAssembly = Assembly.Load(assembly);
}
catch (FileNotFoundException)
{
errorMessage = string.Format("Could not find assembly '{0}'", assembly);
result = null;
return false;
}
What I want to know is if there’s a way to clear the reflection cache without restarting the process. Any help would be greatly appreciated.
Thanks in advance!
You can’t unload assemblies in .Net – you can however shut down an app domain (which is where assemblies are loaded into).