Welcome to Typemock Answers. Here you can ask and receive answers from other community members. And if you liked or disliked an answer or thread: react with an up- or downvote Enjoy!

Error in faking the manage object

0 votes

I have a test that uses a c++ managed wrapper (which has unmanaged members)

Now, I would like to Isolate the c++ managed wrapper and run my test.

 

I mytest, I have the following lines, I want to mock the GetReaderInfo of ManagedWrapper

            var fakeReader = Isolate.Fake.Instance<Reader>(Members.ReturnRecursiveFakes);
            Isolate.Swap.AllInstances<Reader>().With(fakeReader);
            Isolate.WhenCalled(() => fakeReader.GetReaderInfo()).WillReturn(myreaderinfo);
 
I get the following error 
 
----------------------------------------------------------------------------8<--------------------------------------------------------------------------------
Test Name: TestMethod
Test FullName: UnitTests.namespace1.TestClass.TestMethod
Test Source: j:\filepath : line xx
Test Outcome: Failed
Test Duration: 0:00:xx.xx
 
Result Message:
Test method namespace.TestMethod threw exception: 
System.BadImageFormatException: Could not load file or assembly 'ManagedWrapper, Version=x.x.x.x, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.
TestCleanup method Product.UnitTests.namespace1.TestClass.TestCleanup threw exception. System.TypeInitializationException: System.TypeInitializationException: The type initializer for 'namespace2.WrapperManager' threw an exception. ---> System.BadImageFormatException: Could not load file or assembly 'ManagedWrapper, Version=x.x.x.x, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format..
Result StackTrace:
at UnitTests.namespace1.TestClass.TestMethod()
 
TestCleanup Stack Trace
   at TypeMock.MockManager.getReturn(Object context, String typeName, String methodName, Object methodGenericParams, Boolean isDecorated, Boolean isInterceptedType, Object[] methodArguments)
   at Typemock.Interceptors.Profiler.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected, Boolean isInterceptedType)
   at UnitTests.namespace1.TestClass.TestCleanup() in j:\filepath.cs:line xx
---------------------------------------------------------------------------->8--------------------------------------------------------------------------------

 

asked Sep 1, 2016 by tsgd84 (120 points)

1 Answer

0 votes
Hi,

From the exception I see you need to check if you run your test under correct processor architecture. If your unmanaged members are against x64 it shoud be x64 as well.

Also, you can use Fusion Log Viewer to see eaxctly wich assembly it failed to load.
answered Sep 4, 2016 by eva (1,580 points)
...