Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8383541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:11:17+00:00 2026-06-09T17:11:17+00:00

Today I got a very weird problem which I was able to solve, but

  • 0

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:

EDIT

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:

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<T> {

        public virtual IEnumerable<T> GetData() {
            yield break;
        }
    }

    class ImplementingImporter : BaseClassImporter<int> {
        public override IEnumerable<int> GetData() {
            // iterating seems to cause the problem
            foreach(var dataByBaseImpl in base.GetData()) {
                yield return dataByBaseImpl;
            }
        }
    }
}

I get the following error:

System.BadImageFormatException: An attempt was made to load a program
with an incorrect format. (Exception from HRESULT: 0x8007000B)

When I change the code from the used importer to it works:

class ImplementingImporter : BaseClassImporter<int> {
    protected override IEnumerable<int> GetData() {
        return base.GetData();
    }
}

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.

I guess it has something to do with the generated IL code but I cannot think of the scenario that is causing the Problem.

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.

EDIT:

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.

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:11:18+00:00Added an answer on June 9, 2026 at 5:11 pm

    This appears to be a bug with the yield return statement:

    https://connect.microsoft.com/VisualStudio/feedback/details/677532/an-attempt-was-made-to-load-a-program-with-an-incorrect-format-exception-from-hresult-0x8007000b#details

    They state it is fixed in VS2012 (or “the version after VS 2010”).

    I am running a console application targeting .NET Framework 4 using VS2010 SP1 and can confirm I get the same error as you. I do not have a VS2012 install available to try this with.

    A similar-ish question has been asked here:

    Iterator blocks and inheritance

    Another suspiciously similar example (this time with async, but triggered on MoveNext again):

    C#5 AsyncCtp BadImageFormatException

    Other resources:

    • German connect entry.
    • Linked MSFT forum post from above (use translate).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today I got this question for which I think I answered very bad. I
I got this code today that works for jQuery v7. The problem is that
I though it would be very simple but I can not get it today.
Learning this very slowly... got some books today and they just plain suck.. so..
I got into this not very good situation.. When web application starts - I
Today I got into a very interesting conversation with a coworker, of which one
Today I've got a stacktrace with a very strange error. Actually, I may be
I got a problem today. It had a method and I need to find
i got a strange Problem using Jain Sip (dowload today Version Jain-sip-ri-1.2.2014.jar). I'm connecting
I've got a very annoying problem with my Zend studio. I have a zend

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.