I\'m mocking VSTO objects and in one project (I didn\'t write) it has this code:
var listOfSheets = new List();
var mockSheets = Substitute.
Sounds like the following may be the cause:
VSTO Specific Project to be tested (Addin/taskpane/etc)
VSTO ver: VSTO 3.0 SP1
.NET ver: .NET 3.5 SP1
VS 2010 Test project for project above
defaults to
.NET Ver: .NET 4.0
This would create a referencing problem when going to mock up the objects as the test project is expecting to be able to use MS.Csharp (i guess) and possibly other references.
So the exception is not really refering to the Null value returned by the mock object at all, but rather a null binding exception caused by not being able to load .NET 4.0's CSharp library.
Therefore as you discovered the solution is to remove .net 4.0 Csharp reference. It is perhaps unnecessary although to set the project to run under .net 3.5? Not sure you would have to test if any other problems occur. But I guess better to keep test projects on .net 4 if you can. Unless someone can indicate if this is not best practise.