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
0 votes
Hi,

I'm getting a TypeLoadException exception in my unit test when TypeMock is enabled even when I'm not mocking anything and don't even reference the TypeMock dll. Here's the text of the exception:
Test method TestProject1.MyClassTest.method1Test threw exception: System.TypeLoadException: Could not load type 'ConsoleApplication6.MyClass`1' from assembly 'ConsoleApplication6, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' due to value type mismatch..

This problem is present when using either TypeMock version 3.6.1 or 3.7.1 using .Net 2.0. It goes away if I disable TypeMock in the Visual Studio Tools menu. The problem also disappears if I turn on logging in TypeMock. This is very similar to the issue reported in the third message in this thread:
https://www.typemock.com/community/viewtopic.php?t=327
The difference though is that I'm not using either ReSharper or NUnit. I'm simply running the test in Visual Studio.

Here's a small test case that demonstrates the problem. The following is the code being tested:
    public class MyBase<D>
    {
    }

    public class MyClass<D> : MyBase<D>
    {
        private int var;
        public int Prop
        {
            set
            {
                var = value;
            }
        }

        public static void method1(string s)
        {
            MyClass<D> foo = new MyClass<D>();
            foo.Prop = int.Parse(s);
        }
    }

And this is the test method:
        [TestMethod()]
        public void method1Test()
        {
            MyClass<int>.method1("42");
        }

Note that the code under test must be in a different dll than the test method to see the problem. If they are in the same dll the exception will not occur. Having a generic base class is also key.

Thanks for your help in advance.
asked by tibor (1.8k points)

3 Answers

0 votes
Hi
We will fix the problem and I will send you the patch offline
Thanks for reporting the problem.
answered by ohad (35.4k points)
0 votes
I am encountering the same issue. Can I get that patch?
answered by RobCannon (140 points)
0 votes
Hi
Unfortunately we haven't solved the bug just yet.
Please note that even though you got the same exception it is possible that you are dealing with different problem.

Can you please give us more details about the bug?
When it happens? Or a code example that creates the bug.
I'll send you my mail address in case you prefer to do it by mail.
answered by ohad (35.4k points)
...