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 947819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:08:29+00:00 2026-05-15T23:08:29+00:00

I am trying to re-create a TypeLoadException for demonstration purposes, so I have a

  • 0

I am trying to re-create a TypeLoadException for demonstration purposes, so I have a ridiculously goofy library setup that looks like this:

TestProject --> TheLibrary [1.0]
            \-> ProxyForV2 -> TheLibrary [2.0]

TheLibrary version 1 has these relevant interfaces:

public interface IConsistentThing
{
    int ConsistentProperty { get; set; }
}

public interface IShrinkingThing
{
    int RemovedProperty { get; set; }
}

While version 2 of TheLibrary‘s interfaces look like:

public interface IConsistentThing
{
    int ConsistentProperty { get; set; }
}

public interface IShrinkingThing
{ }

ProxyForV2 has this class which implements the version 2.0 IShrinkingThing:

public class ShrinkingThingImpl : IShrinkingThing
{
    public int ConsistentProperty { get; set; }
}

So, in TestProject, I am expecting to cause a TypeLoadException if someone tries to assign a ProxyForV2.ShrinkingThingImpl, since the first version of the interface has a property that is not implemented by the second version. To prove this, I have a unit test which looks like:

[TestMethod]
public void ShrinkingThingBreaks()
{
    try
    {
        IShrinkingThing thing = new ProxyForV2.ShrinkingThingImpl();

        Assert.Fail("This should have caused a TypeLoadException");
    }
    catch (TypeLoadException)
    {
        //  valid
    }
}

Here’s my problem: this unit test fails. But not due to the my Assert.Fail, as I would expect it to. The test output looks like this:

Test method TestProject.LoadTester.ShrinkingThingBreaks threw exception: System.TypeLoadException: Method ‘get_RemovedProperty’ in type ‘ProxyForV2.ShrinkingThingImpl’ from assembly ‘ProxyForV2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ does not have an implementation..

So a TypeLoadException is being thrown and although the only place it could possibly be thrown is in a try block with a catch (TypeLoadException), the exception refuses to be caught. Beyond that, even if I use a catch-all, the unit test fails with the same error as before:

[TestMethod]
public void ShrinkingThingBreaks()
{
    try
    {
        IShrinkingThing thing = new ProxyForV2.ShrinkingThingImpl();

        Assert.Fail("This should have caused a TypeLoadException");
    }
    catch
    {
        //  valid
    }
}

What is going on? Obviously, this is a completely contrived scenario, but I would still like to know what is going on so that this error can be avoided at run time or at least dealt with if it happens (yes, I’m aware the ultimate solution is to make sure all your library versions are the same).

The worst part is that any access to the class at all, such as typeof(ProxyForV2.ConsistentThingImpl) or ProxyForV2.ConsistentThingImpl.SomeStaticFunction() causes this un-catchable TypeLoadException, so it is clear that the problem originates when .NET tries to load the class at all, not from any assignment.

My only idea for mitigating this issue is to try to load the type in a different application domain so that it does not interfere and then do some crazy reflection stuff to see if the interface is compatible with the implementation, but that seems like complete and total overkill.

In summary: Why does it seem impossible to catch this problem in the “normal” way and how can I resolve issues like this at runtime?

  • 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-05-15T23:08:30+00:00Added an answer on May 15, 2026 at 11:08 pm

    The types get loaded before execution begins on the method that uses them. To do this, you need to:

    [TestMethod]
    public void ShrinkingThingBreaks()
    {
        try
        {
            InnerShrinkingThingBreaks();
    
            Assert.Fail("This should have caused a TypeLoadException");
        }
        catch
        {
            //  valid
        }
    }
    
    [MethodImpl(MethodImplAttributes.NoInlining)]
    private void InnerShrinkingThingBreaks()
    {
            IShrinkingThing thing = new ProxyForV2.ShrinkingThingImpl();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying create a table and add this table into tablecell (table inside
I'm trying create a regex that verifies an xml entity name is valid (see
I'm trying create a small http proxy service. This is not working so well.
Hi I am trying create a system call that will count the number of
I am trying create a Regex-based replacement for an article to automatically convert embedded
I am trying create an application which will clone the GIT repository to the
I am trying create a prototype where one of the features is a dropdown
In a multi form .NetCF 3.5 application I'm trying create the forms in the
Trying to create an object from an HQL query, but just can't figure out
I am new to PHP so please forgive if this question or problem seem

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.