Assembly Reference + Variable vs. Assembly.Load

235 views Asked by At

I've got some assemblies that load which take a while to load because they're a third party framework with large file sizes. In order to eliminate pausing the first time something using them is accessed in the application, I decided to cause them to load on application start-up. In fact, to generally improve performance (no memory concerns here) I decided to have all referenced assemblies for the AppDomain get loaded via Assembly.Load and their dependencies recursively as well (with code to avoid duplicates, etc.).

That all works just fine.

I was refactoring the code to use a custom AssemblyInfo object so that I could store more information about the assemblies that are loaded, and I had a thought.

When you have a reference to an Assembly type object, is that assembly then loaded into memory? If so, then all I need to do is maintain live references to each assembly rather than taking the Assembly.FullName and feeding it into Assembly.Load, which would then be a redundant practice as we've already got Assembly objects.

Now the way we get the Assembly objects from the AppDomain is AppDomain.Current.GetAssemblies();, and I looked in the reference source and found that this calls an extern function:

    [MethodImplAttribute(MethodImplOptions.InternalCall)]
    private extern Assembly[] nGetAssemblies(bool forIntrospection);

Unfortunately I couldn't chase this any further down the rabbit hole, as no references to nGetAssemblies seem to be in CoreCLR source or elsewhere other than the ones in AppDomain and one other strange (but irrelevant-looking) place.

Anybody know any of the following information?

  1. Whether having an Assembly object is as good as running Assembly.Load (are they redundant, even)?
  2. If the Assembly objects are good-to-go after attaining them via AppDomain.Current.GetAssemblies()?
  3. Where nGetAssemblies is, so I could read its code?
  4. If there is a better way to do this than loading all assemblies in the AppDomain, followed by loading all of their dependencies recursively and keeping track of what has been loaded to avoid trying to load the same ones over again?
0

There are 0 answers