Is it possible to get all the referenced assemblies (within a Unit Test project) that have a custom attribute applied. I use the following code withing my application which works successfully:
var assemblies = System.Web.Compilation.BuildManager.GetReferencedAssemblies().Cast<Assembly>().Where(a => a.GetCustomAttributes(false).OfType<AssemblyCategoryAttribute>().Any()).ToList();
However System.Web.Compilation.BuildManager doesn't work in my test project so I tried:
Assembly.GetExecutingAssembly().GetReferencedAssemblies().Select(a => Assembly.ReflectionOnlyLoad(a.FullName).Where(a => a.GetCustomAttributes(false).OfType<AssemblyCategoryAttribute>().Any()).ToList();
But this threw the error:
It is illegal to reflect on the custom attributes of a Type loaded via ReflectionOnlyGetType (see Assembly.ReflectionOnly) -- use CustomAttributeData instead.
I'd appreciate it if someone could show me how to do this. Thanks