Reputation: 2571
We are doing extensive code analysis on a LOT (thousands) of C# projects. But although we are not calling the Solution.Emit() method, assemblies are still loaded into memory. Are there other methods that also cause this behavior? Is it even possible at all to create a compilation and retrieve its symbols, without loading an assembly in memory? Hopefully we can somehow avoid to create separate appdomains and unloading them.
Upvotes: 1
Views: 457
Reputation: 3541
looks like your approach is wrong, you are likely loading the assemblies in the primary AppDomain.
But the documentation How to: Load and unload assemblies says that to unload an assembly you need yo unload the full application domain where those assemblies were loaded. It also links to How to: Unload an Application Domain
So you should:
This is the code from the doc:
Console.WriteLine("Creating new AppDomain.");
AppDomain domain = AppDomain.CreateDomain("MyDomain", null);
Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName);
Console.WriteLine("child domain: " + domain.FriendlyName);
try
{
AppDomain.Unload(domain);
Console.WriteLine();
Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName);
// The following statement creates an exception because the domain no longer exists.
Console.WriteLine("child domain: " + domain.FriendlyName);
}
catch (AppDomainUnloadedException e)
{
Console.WriteLine(e.GetType().FullName);
Console.WriteLine("The appdomain MyDomain does not exist.");
}
Upvotes: 1