Why are some .Net assemblies not available with AppDomain's GetAssemblies () method?

I have a bit of code that traverses the types loaded in the AppDomain that run in an ASP.NET application. This is how I get the assemblies:

var assemblies = AppDomain.CurrentDomain.GetAssemblies();

      

There is no problem when starting the application for the first time 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 are available that I expect. When I go to the debugger, I notice that some assemblies from the private search path (my application's bin directory) were not loaded. I was on the assumption that all assemblies were loaded when the application was started and restarted regardless of whether they were immediately needed. But in case of restart, this doesn't seem to happen unless those build files have been updated.

I need to collect type information at startup for later use. But since the types are not available during restart, this can lead to chaos later when the type information has to be used. So with that in mind, how can I solve or work around this flaw?

+2


source to share


3 answers


As part of the startup, can you explicitly load the assemblies you are interested in?

You will need to know in advance which assemblies you will need.



Scanning the filesystem to see which assemblies were shipped along with your application might be a useful idea, but it won't help the GAC loaded assemblies ...

+2


source


Assemblies are loaded on demand, so it may be that you haven't yet used any of the types contained in those assemblies.



+4


source


you can use

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

      

This way you get all assemblies that are referenced by the assembly you are calling this method from.

+3


source







All Articles