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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:05:07+00:00 2026-05-15T09:05:07+00:00

Update: I’ve filed a bug report on Microsoft Connect: https://connect.microsoft.com/VisualStudio/feedback/details/568271/debugger-halting-on-exception-thrown-inside-methodinfo-invoke#details If you can reproduce

  • 0

Update: I’ve filed a bug report on Microsoft Connect: https://connect.microsoft.com/VisualStudio/feedback/details/568271/debugger-halting-on-exception-thrown-inside-methodinfo-invoke#details

If you can reproduce this problem on your machine, please upvote the bug so it can be fixed!


Ok I’ve done some testing and I’ve reduced the problem to something very simple:

i. Create a method in a new class that throws an exception:

public class Class1 {
    public void CallMe() {
        string blah = null;
        blah.ToLower();
    }
}

ii. Create a MethodInfo that points to this method somewhere else:

Type class1 = typeof( Class1 );
Class1 obj = new Class1();
MethodInfo method = class1.GetMethod( "CallMe" );

iii. Wrap a call to Invoke() in a try/catch block:

try {
    method.Invoke( obj, null ); // exception is not being caught!
} catch {
}

iv. Run the program without the debugger (works fine).

v. Now run the program with the debugger. The debugger will halt the program when the exception occurs, even though it’s wrapped in a catch handler that tries to ignore it. (Even if you put a breakpoint in the catch block it will halt before it reaches it!)

In fact, the exception is happening when you run it without the debugger too. In a simple test project it’s getting ignored at some other level, but if your app has any kind of global exception handling, it will get triggered there as well. [see comments]

This is causing me a real headache because it keeps triggering my app’s crash-handler, not to mention the pain it is to attempt to debug.

  • 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-15T09:05:08+00:00Added an answer on May 15, 2026 at 9:05 am

    I can reproduce this on my .NET 4 box, and you’re right — it only happens on .NET 4.0.

    This smells very much like a bug to me, and should go on MS Connect. Major bummer if this is tripping your crash handler. Sounds like a non-pleasing way to work around this is to wrap the invoked method inside its own handler. 🙁

    One thing I can not reproduce, though, is tripping the crash handler. Here’s my program:

    namespace trash {
        public class Class1 {
            public void CallMe() {
                string blah = null;
                blah.ToLower();
            }
        }
    
        class Program {
            static void Main(string[] args) {
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);           
                var class1 = typeof(Class1);
                var method = class1.GetMethod("CallMe");
    
                try {
                    var obj = new Class1();
                    method.Invoke(obj, null); // exception is not being caught!
                }
                catch (System.Reflection.TargetInvocationException) {
                    Console.Write("what you would expect");
                }
    
            }
    
            static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) {
                Console.Write("it would be horrible if this got tripped but it doesn't!");
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.