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?
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 theAppDomain. Of course, if those assemblies were going to be loaded anyway, there’s no harm done. (Once you’ve loaded the assembly once into anAppDomain, using the sameAssemblyNameagain will just return the already-loaded assembly.)