title: Why does this throw exception
body: <p>The test:</p>
  
  <pre><code>[TestMethod]
  public void TestStringWithValidAndInvalid()
  {
      MockRepository mocks = new MockRepository();
      ICentipedeCore mockCore = mocks.DynamicMock&lt;ICentipedeCore&gt;();
      IPythonEngine pythonEngine = mocks.StrictMock&lt;IPythonEngine&gt;();
      IPythonByteCode mockPythonByteCode = mocks.Stub&lt;IPythonByteCode&gt;();
  
      mockCore.Stub(c =&gt; c.PythonEngine)
              .Return(pythonEngine);
  
      pythonEngine.Expect(e =&gt; e.Compile(Arg&lt;String&gt;.Is.Equal("\"String\""),
                                         Arg&lt;PythonByteCode.SourceCodeType&gt;.Is.Anything))
                  .Return(mockPythonByteCode);
  
      pythonEngine.Expect(e =&gt; e.Evaluate(Arg&lt;IPythonByteCode&gt;.Is.Equal(mockPythonByteCode),
                                          Arg&lt;PythonScope&gt;.Is.Anything))
                  .Return(3);
  
      pythonEngine.Expect(e =&gt; e.Compile(Arg&lt;String&gt;.Is.Equal("this is invalid python"),
                                         Arg&lt;PythonByteCode.SourceCodeType&gt;.Is.Anything))
                  .Throw(new PythonParseException(mocks.Stub&lt;Exception&gt;()));
  
  
      ActionWrapper testAction = new ActionWrapper(mockCore);
  
      var original = @"{1+2} with {invalid python}";
      var expected = "3 with {invalid python}";
      var result = testAction.ParseStringForVariable(original); // ActionTest.cs: line 267
  
      mocks.VerifyAll();
      Assert.AreEqual(expected, result);
  }
  </code></pre>
  
  <p>The method under test (exposed by a wrapper): </p>
  
  <pre><code>protected String ParseStringForVariable([NotNull] String str)
  {
      IPythonEngine pythonEngine = GetCurrentCore().PythonEngine;
  
      for (int i = 0; i &lt; str.Length; i++)
      {
          if (str[i] != '{')
          {
              continue;
          }
  
          int opening = i;
          foreach (var expression in from closing in str.IndexesWhere('}'.Equals)
                                     where closing &gt; opening
                                     select new
                                            {
                                                Template = str.Substring(opening, closing - opening + 1),
                                                Code = str.Substring(opening + 1, closing - opening - 1)
                                            })
          {
              IPythonByteCode compiled;
              try
              {
                  compiled = pythonEngine.Compile(expression.Code, PythonByteCode.SourceCodeType.Expression);
              }
              catch (PythonParseException)
              {
                  // not valid python, try next expression
                  continue;
              }
              dynamic r = pythonEngine.Evaluate(compiled);
              String result = r.ToString(); //  Action.cs: line 217, wrapped at  ActionTest.cs: line 96
              str = str.Replace(expression.Template, result);
              break;
          }
      }
  
      return str;
  }
  </code></pre>
  
  <p>The Exception:</p>
  
  <blockquote>
    <p>Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference</p>
  </blockquote>
  
  <p>The exception is thrown on the line after <code>dynamic r = pythonEngine.Evaluate(compiled);</code> with <code>r</code> being null. but I don't know why - <code>compiled</code> has the same value as mockPythonByteCode, pythonEngine is the mock created in the test, and the identical call works in a different method.  The only difference here, is that <code>pythonEngine.Compile</code> has two Expectations, on different inputs, with different results.</p>
  
  <p>The problem is, I've got <code>TestStringWithValidCode()</code> and <code>TestStringWithInvalidCode()</code>, both working fine, which I merged to form <code>TestStringWithValidAndInvalid()</code>, so each half <strong>should</strong> work.</p>