I have this code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace RegexTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = "The quick brown fox.";
            string pat = "fox";
            Regex rgx = new Regex(pat, RegexOptions.IgnoreCase);
            Match matches = rgx.Match(str);

            Console.ReadKey();
        }
    }
}

It compiles and runs without errors.
I have a breakpoint set at Console.ReadKey(), because I wanted to inspect the variable matches.
But I got the strange error message I put in the title of this thread.
The web wasn't clear about what it meant.

So any help is as always greatly appreciated.

Works fine for me in VS2013 Ultimate running .Net 4.5 console application.

I can access the matches variable and it contains fox as expected... odd.

Make sure you're running it in Debug mode. In Release this could have been optimised away because you're not using the variable.

Comments
Great!

Forgot to mention I used VS2010 Professional.
@Ketsuekiame: Indeed, forgot I stood in Release mode setting in Debug solved it!

This question has already been answered. Start a new discussion instead.