Question

I have a little bit of code that loops through the types currently loaded into an AppDomain that runs in an ASP.NET application. Here's how I get the assemblies:

var assemblies = AppDomain.CurrentDomain.GetAssemblies();

When the application first starts up there is no problem and all the types I expect are present. But when I update the Web.config or kill the w3p.exe process (or the process gets recycled for whatever reason) only some of the types I'm expecting are available. When I step through with a debugger I notice that certain assemblies from the private search path (the bin directory of my application) haven't been loaded. I was under the assumption that all assemblies were loaded at application start and restart whether or not they were immediately required. But in the case of restarting this doesn't seem to be happening unless those assembly files have been updated.

What I require is to collect type information at start-up for use later. But since during a restart the types aren't available it reeks havoc later on when the type information needs to be used. So with that in mind how can I solve or work around this deficiency?

Was it helpful?

Solution

As a part of startup, can you explicitly load the assemblies you care about?

You would have to know ahead of time which assemblies you would need.

Scanning the filesystem to find out which assemblies have been shipped along with your app may be a useful idea, but it won't help for GAC loaded assemblies...

OTHER TIPS

Assemblies are loaded on demand, so it could be that you did not used any type contained in these assemblies yet.

You can use

AssemblyName[] assemblies = Assembly.GetCallingAssembly().GetReferencedAssemblies();

This way, you get all assemblies that are referenced from the assembly from which you are calling these method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top