I am having this same error so I will add few more details...
I am using...
Visual Studio 2008,
Windows XP,
Typemock 5.3.4,
Postsharp 1.5.6.629
This error occurs if you try to Isolate.Fake ANY object anywhere in the test class. Even if that object is not at all contained in the class that has postsharp aspects applied to it.
This is my postsharp aspect attribute
using System;
using PostSharp.Laos;
namespace Common.Aspect
{
[Serializable]
public class AtomicTransactionAttribute : OnMethodBoundaryAspect
{
public override void OnEntry(MethodExecutionEventArgs eventArgs)
{
}
public override void OnExit(MethodExecutionEventArgs eventArgs)
{
}
}
}
This is a class that is decorated with the attribute above
using Common.Aspect;
using System;
namespace Common.Test.Aspect
{
public class NonIValidatorObject
{
public NonIValidatorObject()
{
}
[AtomicTransaction]
public void DoNothing()
{
}
}
}
And here is the unit test code
using Common.Aspect;
using NUnit.Framework;
using TypeMock.ArrangeActAssert;
using System;
namespace Common.Test.Aspect
{
[TestFixture]
public class AtomicTransactionAttributeTests
{
[Test]
public void SomeTest()
{
/*
* Any attempt to fake any object will result in the same error
* Notice that this object is NOT swapped and is not used anywhere
* Its just here to demostrate that trying to use typemock will cause an error
*/
NonIValidatorObject obj = Isolate.Fake.Instance<NonIValidatorObject>();
//DoNothing() is "intercepted" correctly with no error if the line of code above is deleted
NonIValidatorObject target = new NonIValidatorObject();
target.DoNothing();
}
}
}
This is the error that always happens
TestCase 'SomeTest'
failed: System.TypeInitializationException : The type initializer for '<>AspectsImplementationDetails_1' threw an exception.
----> System.NullReferenceException : Object reference not set to an instance of an object.
C:WorkCodesjdirect-common-libraryCommon.TestAspectNonIValidatorObject.cs(32,0): at Common.Test.Aspect.NonIValidatorObject.DoNothing()
C:WorkCodesjdirect-common-libraryCommon.TestAspectAtomicTransactionAttributeTests.cs(53,0): at Common.Test.Aspect.AtomicTransactionAttributeTests.SomeTest()
--NullReferenceException
at bh.a(Object A_0)
at ak.a(Object A_0)
at ak.a(String A_0, Object A_1)
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4)
at TypeMock.InternalMockManager.isMocked(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
at <>AspectsImplementationDetails_1..cctor()