title: How to get custom attributes from an assembly that is not (really) loaded
body: <p>We all know that the assembly can be queried for attributes using the GetCustomAttributes method. I want to use this to identify an extension module for my application. However, to avoid loading every assembly I prefer a defensive approach:</p>
  <ol>
  <li><p>using Assembly.ReflectionOnlyLoadFrom to get more details about an assembly (has it my ModuleAttribute?)</p>
  </li>
  <li><p>if the ModuleAttribute is found, I will finally load it using Assembly.LoadFrom</p>
  </li>
  </ol>
  <p>Unfortunately it seems that there is no way to get the attributes from an assembly, that is loaded into the reflection-only context:</p>
  <pre><code>myAssembly.GetCustomAttributes(typeof(ModuleAttribute), false)
  </code></pre>
  <p>fails with an <code>InvalidOperationException</code></p>
  <blockquote>
  <p>It is illegal to reflect on the custom attributes of a Type loaded via ReflectionOnlyGetType</p>
  </blockquote>
  <p>and</p>
  <pre><code>CustomAttributeData.GetCustomAttributes(myAssembly)
  </code></pre>
  <p>fails with <code>ReflectionTypeLoadException</code> because of dependant assemblies not being loaded.</p>
  <p>So how to get the attributes without</p>
  <ol>
  <li>polluting my application domain with useless (maybe harmful) types by calling Assembly.LoadFrom</li>
  <li>the need to load all referenced assemblies</li>
  <li>the need for separate application domains (gave it a short try, smelled like even more PITA)</li>
  </ol>
  <p>?</p>