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've got a handful of tests that have started throwing a Typemock exception at various points on objects that are not mocked.

The exception details is as follows:

System.NullReferenceException occurred
Message="Object reference not set to an instance of an object."
at bl..cctor()

Removing all references to Typemock resolves the issue, but of course I can no longer run the tests as I need to mock some objects.

I've tried Natural and AAA mocking.

Any ideas?

asked by Imaji (2.2k points)

3 Answers

0 votes
Hi John,

When did you start seeing these issues? was it following a version upgrade or some other change in the project?

Can you post a sample test that causes this issue here?

Typemock Support
answered by doron (17.2k points)
0 votes
Hi Doron,

Nope, no version upgrade we're still using 5.1.2 x64.

It was the beginning of this week. The only thing I've done is to change the way a Unity Container was being populated. It's moved from being from a config file to mocking.

I've also noted that all tests in this test class now throw this error when debugging, but pass when run :(

An example test method (with sanitised types):

public void InitialiseWorkflowRuntime()
m_WorkflowRuntime = new WorkflowRuntime();

// By using a Manual Scheduler, we can make the Activity execute when we want
m_Scheduler = new ManualWorkflowSchedulerService();

m_WorkflowRuntime.WorkflowCompleted += WorkflowCompleted;
m_WorkflowRuntime.WorkflowTerminated += WorkflowTerminated;

m_Exception = null;
m_Result = null;

public void CleanupWorkflowRuntime()
m_WorkflowRuntime.WorkflowCompleted -= WorkflowCompleted;
m_WorkflowRuntime.WorkflowTerminated -= WorkflowTerminated;

public void TestMethod()
UnityContainer populatedContainer = GetPopulatedContainer();

using (RecordExpectations recorder = new RecordExpectations())
UnityContainer unity = new UnityContainer();


Dictionary<string> parameters = new Dictionary<string> { { PropertyName, m_Value } };

WorkflowInstance instance = m_WorkflowRuntime.CreateWorkflow(typeof(Activity), parameters);


Message outputMessage = m_Result[NewMessagePropertyName] as Message;


outputMessage.MessageText = TestMessage;

Assert.AreEqual(expectedResult, builtMessage);

The exception can occur on any of the non mocked object during the TestInitialise or Arrange or during setting the expectations.

answered by Imaji (2.2k points)
0 votes
Hi John,

It might be that Visual Studio debugs with notification on all exceptions.

Is it possible that this is the case when you debug? (In Visual Studio: Debug->Exceptions check if any check box is checked in the Thrown column).

Best Regards,
Typemock Support Team
answered by Elisha (12k points)