Mocked object doesn't have all properties shown in Intellisense - in one project but has them in the other

前端 未结 4 1990
既然无缘
既然无缘 2021-01-16 03:24

I\'m mocking VSTO objects and in one project (I didn\'t write) it has this code:

var listOfSheets = new List();
var mockSheets = Substitute.         


        
4条回答
  •  感情败类
    2021-01-16 03:46

    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
    
    

提交回复
热议问题