Strange Visual Studio 2013 debugger bug

Try debugging the following code on Visual Studio 2013. Make sure you compile to x64 and set a the breakpoint at the var bar =... line. The code should throw an InvalidOperationException but instead gets to Console.WriteLine(). It works fine if you don’t set a breakpoint or just run without the debugger attached.
using System;
 
namespace ConsoleApplication1
{
    public class Foo<T>
    {
        public virtual T GetBar<K>(K foo)
        {
            throw new InvalidOperationException();
        }
    }
 
    class Program
    {
        static void Main(string[] args)
        {
            var foo = new Foo<string>();
 
            // Place a break point on this line and then step over.
            // An exception should throw but it doesn't.
            // If you try to step into instead it will not go into GetBar()
            // The instruction pointer is buggered.
            var bar = foo.GetBar(new Guid());
 
            Console.WriteLine("Should not get here");
        }
    }
}

Leave a Reply

Your email address will not be published.