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 run into a problem using TypeMock with certain method calls. The problem appears when making a call with seven 'out' parameters (fewer are fine!). I built a solution demonstrating the problem and included the class below. It seems that running the MockManager.Init call messes with this particular IL in such a way that the CLR sees it as invalid. This occurs even without using any mocks, the Init call is enough.

The exception takes out the NUnit console runner with:

TargetInvocationException : Exception has been thrown by the target of an invocation. ---> System.InvalidProgramException: Common Language Runtime detected an invalid program.

Then lots of null reference exceptions in the finalizers.

using System;
using TypeMock;

namespace MockFix
{
class Class1 {
public static void Main(string[] args) { }
}

[NUnit.Framework.TestFixture]
public class TestClass
{
[NUnit.Framework.Test]
public void TheTest()
{
Class1 passInFine1;
Class1 passInFine2;
Class1 passInFine3;
Class1 passInFine4;
Class1 passInFine5;
Class1 passInFine6;

Class1 passInFail1;
Class1 passInFail2;
Class1 passInFail3;
Class1 passInFail4;
Class1 passInFail5;
Class1 passInFail6;
Class1 passInFail7;

Console.WriteLine("Do six out arguments");
TargetWithSixArguments(out passInFine1, out passInFine2, out passInFine3, out passInFine4, out passInFine5, out passInFine6);

Console.WriteLine("Init the MockManager");
MockManager.Init();

Console.WriteLine("Do six out arguments");
TargetWithSixArguments(out passInFine1, out passInFine2, out passInFine3, out passInFine4, out passInFine5, out passInFine6);

Console.WriteLine("Do seven out arguments");
//This fails.
TargetWithSevenArguments(out passInFail1, out passInFail2, out passInFail3, out passInFail4, out passInFail5, out passInFail6, out passInFail7);


Console.WriteLine("Done...readline");
Console.ReadLine();
}

private void TargetWithSixArguments(
out Class1 passInFine1,
out Class1 passInFine2,
out Class1 passInFine3,
out Class1 passInFine4,
out Class1 passInFine5,
out Class1 passInFine6)
{
passInFine1 = null;
passInFine2 = null;
passInFine3 = null;
passInFine4 = null;
passInFine5 = null;
passInFine6 = null;
}

private void TargetWithSevenArguments(
out Class1 passInFail1,
out Class1 passInFail2,
out Class1 passInFail3,
out Class1 passInFail4,
out Class1 passInFail5,
out Class1 passInFail6,
out Class1 passInFail7)
{
passInFail1 = null;
passInFail2 = null;
passInFail3 = null;
passInFail4 = null;
passInFail5 = null;
passInFail6 = null;
passInFail7 = null;
}

}
}

output from TypeMock.out

MockFix.TestClass instance void TargetWithSevenArguments(class M&,class M&,class M&,class M&,class M&,class M&,class M&)
PreCompiled: System.NullReferenceException instance void .ctor()
PreCompiled: System.Environment class System.String GetResourceString(class System.String)
PreCompiled: System.Environment class S InitResourceManager()
PreCompiled: System.Resources.ResourceManager instance class System.String GetString(class System.String,class S)
PreCompiled: System.Resources.NeutralResourcesLanguageAttribute instance void .ctor(class System.String)
PreCompiled: System.Resources.RuntimeResourceSet instance class System.String GetString(class System.String,bool)
PreCompiled: System.Reflection.TargetInvocationException instance void .ctor(class S)
PreCompiled: System.Exception instance void .ctor(class System.String,class S)
PreCompiled: System.ApplicationException instance void .ctor(class System.String,class S)
NUnit.Core.NormalTestCase instance void ProcessException(class S,class N)
NUnit.Core.TemplateTestCase instance void RecordException(class S,class N)
NUnit.Core.TemplateTestCase instance void doTearDown(class N)
NUnit.Core.TemplateTestCase instance void RecordException(class S,class N)
PreCompiled: System.Exception instance void GetObjectData(class S,value class S)
PreCompiled: System.Environment class System.String GetStackTrace(class S)
PreCompiled: System.Security.Permissions.ReflectionPermission instance void FromXml(class S)
PreCompiled: System.Security.Permissions.ReflectionPermission instance bool IsSubsetOf(class S)
PreCompiled: System.Diagnostics.StackTrace instance void .ctor(class S,bool)
PreCompiled: System.Diagnostics.StackTrace instance void CaptureStackTrace(int32,bool,class S,class S)
PreCompiled: System.Diagnostics.StackFrameHelper instance void .ctor(bool,class S)
PreCompiled: System.Diagnostics.StackFrameHelper instance int32 GetNumberOfFrames()
PreCompiled: System.Diagnostics.StackFrame instance void InitMembers()
PreCompiled: System.Diagnostics.StackFrameHelper instance class S GetMethodBase(int32)
PreCompiled: System.Diagnostics.StackFrame instance void SetMethodBase(class S)
PreCompiled: System.Diagnostics.StackFrameHelper instance int32 GetOffset(int32)
PreCompiled: System.Diagnostics.StackFrame instance void SetOffset(int32)
PreCompiled: System.Diagnostics.StackFrameHelper instance int32 GetILOffset(int32)
PreCompiled: System.Diagnostics.StackFrame instance void SetILOffset(int32)
PreCompiled: System.Diagnostics.StackFrameHelper instance class System.String GetFilename(int32)
PreCompiled: System.Diagnostics.StackFrame instance void SetFileName(class System.String)
PreCompiled: System.Diagnostics.StackFrameHelper instance int32 GetLineNumber(int32)
PreCompiled: System.Diagnostics.StackFrame instance void SetLineNumber(int32)
PreCompiled: System.Diagnostics.StackFrameHelper instance int32 GetColumnNumber(int32)
PreCompiled: System.Diagnostics.StackFrame instance void SetColumnNumber(int32)
PreCompiled: System.Diagnostics.StackTrace instance int32 get_FrameCount()
PreCompiled: System.Diagnostics.StackTrace instance class S GetFrame(int32)
PreCompiled: System.Diagnostics.StackFrame instance class S GetMethod()
PreCompiled: System.Security.SecurityRuntime bool FrameDescSetHelper(class S,class S,class S&)
PreCompiled: System.Reflection.ParameterInfo instance class System.String get_Name()
PreCompiled: System.Diagnostics.StackFrame instance int32 GetILOffset()
PreCompiled: System.Diagnostics.StackFrame instance class System.String GetFileName()
PreCompiled: System.Exception instance class System.String get_Source()
PreCompiled: System.Exception instance class System.String GetExceptionMethodString()
PreCompiled: System.Exception instance class S GetTargetSiteInternal()
PreCompiled: System.Text.StringBuilder instance class S Append(int32)
PreCompiled: System.Diagnostics.StackFrame instance int32 GetFileLineNumber()
PreCompiled: System.Text.UTF8Encoding+UTF8Encoder instance int32 GetBytes(wchar[],int32,int32,unsigned int8[],int32,bool)
PreCompiled: System.Text.UTF8Encoding instance int32 GetBytes(wchar[],int32,int32,unsigned int8[],int32,class U)
PreCompiled: System.NullReferenceException instance void .ctor(class S,value class S)
PreCompiled: System.SystemException instance void .ctor(class S,value class S)
PreCompiled: System.Exception in
asked by cgravill_servotest (600 points)

3 Answers

0 votes
ITargetInvocationException : Exception has been thrown by the target of an invocation. ---> System.InvalidProgramException: Common Language Runtime detected an invalid program.

Hi,

This is a bug, :twisted:
We will fix it and post the fix on the web.

Thanks for posting the example
answered by richard (3.9k points)
0 votes
Taken offline.
answered by richard (3.9k points)
0 votes
Hi,
This is fixed in TypeMock version 2.2.2.0 :D
answered by richard (3.9k points)
...