I tried to mock an interface that accepts DateTimeOffset? as one of its parameters. Suddenly, Visual Studio started reporting "Internal Compiler Error" and that it "stopped working." After many tests, I started deleting files one by one, and then code by line. It comes down to the code below that reproduces this error:
public class testClass { public interface ITest { void Test(DateTimeOffset? date); } public void test2() { var mock = new Mock<ITest>(); mock.Setup(x => x.Test(new DateTime(2012, 1, 1))); } }
The problem seems to be in the line:
mock.Setup(x => x.Test(new DateTime(2012, 1, 1)));
If I comment on this, the compiler works fine. Also, the problem is that I am setting up a new DateTime() that fits in a DateTimeOffset .
Is this a bug in Moq or VS2012 ? Has anyone ever received this error before?
UPDATE
The following code example also leads to a compilation error, both with the regular Visual Studio 2012 compiler and with Roslyn CTP September 2012:
using System; using System.Linq.Expressions; public interface ITest { void Test(DateTimeOffset? date); } public class TestClass { Expression<Action<ITest>> t = x => x.Test(new DateTime(2012, 1, 1)); }
Mistake:
1> CSC: error CS0583: Internal compiler error (0xc0000005 at address 00D77AFB): the likely culprit is "BIND".
This code has nothing to do with Moq.
Karl cassar
source share