sourcenouveau
sourcenouveau

Reputation: 30504

Getting an assembly's Product property only having an AssemblyName

I'm getting the Product attribute from all the loaded assemblies in my application using:

AssemblyProductAttribute product
    = (AssemblyProductAttribute)Attribute.GetCustomAttribute(
        assembly, typeof(AssemblyProductAttribute));

I would like to get this attribute for all the assemblies that the currently loaded assemblies reference. However GetReferencedAssemblies() returns an array of AssemblyNames, so I can't use the above code to get the Product attribute.

Is there a way to get an Assembly object from an AssemblyName object, or a way to get the Product attribute from an AssemblyName?

Upvotes: 1

Views: 2237

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1499770

Well you can use Assembly.Load(AssemblyName) to load the assembly - is that good enough for you? Note that once you've loaded the assembly, you won't be able to unload it other than by unloading the AppDomain. Of course, if those assemblies were going to be loaded anyway, there's no harm done. (Once you've loaded the assembly once into an AppDomain, using the same AssemblyName again will just return the already-loaded assembly.)

Upvotes: 1

Related Questions