title: BadImageFormatException when using IEnumerable and Multi Inheritance
body: <p>Today I got a very weird problem which I was able to solve, but I still do not understand why this is happening. This is the scenario:</p>
  
  <h2>EDIT</h2>
  
  <p>I changed the scenario to be much simpler:
  I have a Program that executes the code, and 2 Importers, a base class with a generic type and another class (ImplementingImporter) that just calls the base method and iterates over it. 
  This is the complete code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace IEnumeratorLoadProblem {
      class Program {
          static void Main(string[] args) {
  
              var importer = new ImplementingImporter();
              try {
                  var data = importer.GetData().ToArray();
              } catch (BadImageFormatException ex) {                
                  Console.WriteLine("Why does this fail? " + ex.ToString());
              }
  
              Console.WriteLine("Press enter to quit");
              Console.ReadLine();
          }
      }
  
      class BaseClassImporter&lt;T&gt; {
  
          public virtual IEnumerable&lt;T&gt; GetData() {
              yield break;
          }
      }
  
      class ImplementingImporter : BaseClassImporter&lt;int&gt; {
          public override IEnumerable&lt;int&gt; GetData() {
              // iterating seems to cause the problem
              foreach(var dataByBaseImpl in base.GetData()) {
                  yield return dataByBaseImpl;
              }
          }
      }
  }
  </code></pre>
  
  <p>I get the following error:</p>
  
  <blockquote>
    <p>System.BadImageFormatException: An attempt was made to load a program
    with an incorrect format. (Exception from HRESULT: 0x8007000B)</p>
  </blockquote>
  
  <p>When I change the code from the used importer to it <strong>works</strong>:</p>
  
  <pre><code>class ImplementingImporter : BaseClassImporter&lt;int&gt; {
      protected override IEnumerable&lt;int&gt; GetData() {
          return base.GetData();
      }
  }
  </code></pre>
  
  <p>Unfortunately I was not able to look at the generated IL Code, because both ILSpy and Reflector.NET (Version 6) displayed an internal error (I think it was anArgumentOutOfRangeException). I was afraid to use ildasm, so I did not try to look at the IL Code directly.</p>
  
  <p>I guess it has something to do with the generated IL code but I cannot think of the scenario that is causing the Problem.</p>
  
  <p>Any ideas what is happening here?
  If the scenario is not clear enough please leave a comment and I will try to make it clearer.</p>
  
  <h2>EDIT:</h2>
  
  <p>Used .NET version: 4.0. The Application is a ConsoleApplication using VS 2010 SP1.
  Build Platform target is AnyCPu, but the problem also shows up when using x86.
  My machine has a 64 bit System (Windows 7).
  The exception also occurs when using .NET 4.0 client profile.</p>
  
  <p>The example is a single project, no external/unmanaged libraries are used, therefore only the suggested problems (e.g. referencing a 32 bit assembly when running 64 bit) should not occur.</p>