chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes

I have the following line of code for mocking SampleClass 

SampleClass mockInst =
               RecorderManager.CreateMockedObject<SampleClass>(Constructor.Mocked) as SampleClass;
 
It throws an exception of type TypeMockException with the following message
 
"Cannot mock constructor of COM types. Set constructor of DMPinMapClass to original behavior".
 
If the change this code like below error is not thrown
 
SampleClass mockInst =
               RecorderManager.CreateMockedObject<SampleClass>(Constructor.NotMocked) as SampleClass;
 
Instead error is thrown in the following record block line number two.
 
 
 
           MockContextManager contextMgr = new MockContextManager ();
 
            using (RecordExpectations recorder = RecorderManager.StartRecording ())
            {
                dummy = contextMgr.FindSheet<SampleClass>();
                recorder.Return(mockInst);
            }
 
SampleClass is a COM class and I dont want itz constructor to be mocked. But I need the FindSheet to return a mocked instance of it with out any error. Could anyone help me in this
asked by thomasjohnaj (1.6k points)

1 Answer

0 votes

Hi Thomas,

Which error do you get when with Constructor.NotMocked?

answered by alex (17k points)

The same errror but in this line

 dummy = contextMgr.FindSheet<SampleClass>();

Hi Alex,

         I was not able to get a resolution for this error. Could you help me in this?

Regards,

Thomas
...