title: Determine the load context of an assembly
body: <p>Given a loaded <code>Assembly</code> is there a way (in code) to determine which of the 3 load contexts it was loaded into (default <strong>Load</strong>, <strong>LoadFrom,</strong> or <strong>Neither</strong>)?</p>
  
  <p>In <a href="https://web.archive.org/web/20190124235454/https://blogs.msdn.microsoft.com/suzcook/2003/05/29/choosing-a-binding-context/" rel="nofollow noreferrer">Suzanne Cook's "Choosing a Binding Context"</a> article, there are some disadvantages that occur when an assembly is loaded into the <strong>LoadFrom</strong>.  In particular, my library uses deserialization and encounters an <code>InvalidCastException</code> when loaded into the <strong>LoadFrom</strong> context.  </p>
  
  <p>Currently my library fails very late (it fails when it executes the problematic deserialization code--see <a href="https://stackoverflow.com/questions/23255892/how-to-reproduce-invalidcastexception-when-binding-to-an-assembly-in-the-loadfro">my example</a>).  I'd like to make it fail much earlier in these circumstances by detecting the context it is loaded into and throwing an exception if it is not loaded into the default <strong>Load</strong> context.</p>