title: Unity Application Block: Exception occurred while resolving: BadImageFormatException
body: <p>I'm using Unity 2.1 in my application and receive the error in the title for one resolving scenario. I have no idea on where to look.</p>
  
  <ul>
  <li>I'm running Windows 7 64bit</li>
  <li>32-bit applications are <strong>enabled</strong></li>
  <li>Tried building against "Any CPU" <em>and</em> "x64"</li>
  </ul>
  
  <p><strong>The problem doesn't seem to be related to the 64bit architecture. Any assistance would be greatly appreciated!</strong></p>
  
  <h1>Scenario's</h1>
  
  <pre><code>//works: class = "ProductManager&lt;Product&gt;
  Container.Resolve&lt;IProductManager&lt;Product&gt;&gt;()
  
  //works: class = "OrderManager"
  Container.Resolve&lt;IOrderManager()
  
  //works: class="OrderManager" 
  Container.Resolve&lt;IOrderManager("OrderManager")
  
  //DOESN'T WORK: EXCEPTION: BadImageFormatException
  Container.Resolve&lt;IOrderManager("OrderManager") 
  
  //works: class="GenericOrderManager&lt;Order&gt;" (obviously)
  var manager = new GenericOrderManager&lt;Order&gt;();
  </code></pre>
  
  <h1>Code</h1>
  
  <p><strong>Unity.config</strong></p>
  
  <pre><code>&lt;alias name="IProductManager" type="Assembly1.Namespace.IProductManager`1" /&gt;
  &lt;alias name="ProductManager" type="Assembly2.Namespace.ProductManager`1" /&gt;
  
  &lt;alias name="IOrderManager" type="Assembly1.Namespace.IOrderManager" /&gt;
  &lt;alias name="OrderManager" 
         type="Assembly1.Namespace.OrderManager" /&gt;
  &lt;alias name="OrderManager" 
         type="Assembly1.Namespace.OrderManager" 
         name="OrderManager" /&gt;
  &lt;alias name="GenericOrderManager" 
         type="Assembly2.Namespace.GenericOrderManager`1"
         name="GenericOrderManager" /&gt;
  </code></pre>
  
  <p><strong>ProductManager + Interface</strong></p>
  
  <pre><code>public interface IProductManager&lt;TProduct&gt; where TProduct : Product
  {
  }
  
  public class ProductManager&lt;TProduct&gt; : IProductManager&lt;TProduct&gt; where TProduct : Product
  {
  }
  </code></pre>
  
  <p><strong>OrderManager + Interface</strong></p>
  
  <pre><code>public interface IOrderManager
  {
  }
  
  public class OrderManager : IOrderManager
  {
  }
  
  public class OrderManager&lt;TOrder&gt; : OrderManager where TOrder : Order
  {
  }
  </code></pre>
  
  <p><strong>Update with StackTrace:</strong></p>
  
  <blockquote>
    <p>at
    System.Runtime.CompilerServices.RuntimeHelpers._CompileMethod(IRuntimeMethodInfo
    method)    at System.Reflection.Emit.DynamicMethod.CreateDelegate(Type
    delegateType)    at
    Microsoft.Practices.ObjectBuilder2.DynamicBuildPlanGenerationContext.GetBuildMethod()
    at
    Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext
    context, NamedTypeBuildKey buildKey)    at
    Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext
    context)    at
    Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext
    context)    at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type
    t, Object existing, String name, IEnumerable`1 resolverOverrides)</p>
  </blockquote>