tags:

views:

64

answers:

2

I am building a Visual Studio editor extension for my Django rendering engine. I just started it so so far it is really simple and so far it does what I expect it to do - highlighting and the such. Or it did until I started to add parsing logic. Part of the parsing relies on regular expressions. And here is my problem: No matter how I try - static variables, member variables, - anything, every time I call new Regex it gives me "Object not set to an instance" exception. Is there a problem with using regular expressions (RegEx) in MEF?

here you go:

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

 namespace NDjango.Designer.Parsing
 {
     public interface IParser
     {
          List<Token> Parse(IEnumerable<string> template);
     }

     [Export(typeof(IParser))]
     public class Parser : IParser
     {
         public List<Token> Parse(IEnumerable<string> template)
         {
             var result = new List<Token>();
             Regex tag_re = new Regex("({{.*}}", RegexOptions.Compiled);
             return result;
         }
     }
 }

A breakpoint on the line with the Regex constructor is hit just fine. The next F10 gives the exception

+1  A: 

No, there is no issue with using regular expressions in MEF. The issue is in your code.

Based on the error message it looks like you are hitting a null reference exception when you try and create a new regex. Without seeing a code sample it's not easy to know what exactly is going wrong.

Can you post a code sample?

JaredPar
sure here it is:namespace NDjango.Designer.Parsing{ [Export(typeof(IParser))] public class Parser : IParser { public List<Token> Parse(IEnumerable<string> template) { var result = new List<Token>(); Regex tag_re = new Regex("({{.*}}", RegexOptions.Compiled); return result; } }}When I put the breakpoint on the new Regex line it hits it just fine, but the next F10 - boom!!!
mfeingold
Sorry for the formatting
mfeingold
@mfeingold - The appropriate way to publish this code snippet would be to edit your question and add it there.
Scott Whitlock
A: 

I am sorry guys, I figured it out, JaredPar you were right - the problem was unbalanced paren in the regexp. The "diagnostic" though was quiet misleading to say the least

mfeingold