I\'m mocking VSTO objects and in one project (I didn\'t write) it has this code:
var listOfSheets = new List();
var mockSheets = Substitute.
This is a reminder to myself everytime I write Nsubstitute Excel Unit Tests. I have battled with this error too many times.
You will get the error: Cannot perform runtime binding on a null reference
When you have referened the .Net Excel Object Library, you MUST reference the COM Microsoft Excel 14.0 Object Library. Once the COM interop Excel DLL is referenced, click F4 to see the DLLs Properties, remember to set the COM Interop NOT to Embed Interop Types.
.Excel Here is a working Project file:
..\..\Refs\Microsoft.Office.Interop.Excel.Extensions.dll
..\..\Refs\NSubstitute.dll
3.5
False
{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}
2
4
0
primary
False
{00020813-0000-0000-C000-000000000046}
1
6
0
primary
False
The offender is this .Net Interop reference (needs to be the COM reference):
True