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
Hello,

I'm trying to learn TDD. I 've read all the docs I found out but I can't understand why I've got a problem with my first test !

Thanks for your help.

Error text:
------------
TestCase 'IHM_tests.TestsControleur.Init_test_V1' failed: System.BadImageFormatException: Bad class token.
   at IHM.Controleur.set_ConstruireEstAutorisé(Boolean value)
   [...]Controleur.vb(9,0): at IHM.Controleur..ctor(IAfficheur unAfficheur) [[ERROR 1]]
   [...]TestsControleur.vb(31,0): at IHM_tests.TestsControleur.Init_test_V1() [[ERROR 2]] 


Code text (VB.NET in VS2005 with TypeMock 3.0 and TestDriven.NET 2.0)
-----------
<Test> _
Public Sub Init_test_V1()
    MockManager.Init()
    Dim mockIAfficheur As MockObject = MockManager.MockObject(GetType(IHM.IAfficheur))
        mockIAfficheur.ExpectSet("ConstruireEstAutorisé").Args(True)
        Dim monControlleur As IHM.Controleur = New IHM.Controleur(CType(mockIAfficheur.Object, IHM.IAfficheur)) [[ERROR 2]]
        mockIAfficheur.Verify()
    End Sub

Public Interface IAfficheur
    Property ConstruireEstAutorisé() As Boolean
End Interface

Public Class Controleur
    Private monAfficheur As IAfficheur
    Private monConstruireEstAutorisé As Boolean

    Public Sub New(ByVal unAfficheur As IAfficheur)
        monAfficheur = unAfficheur
        ConstruireEstAutorisé = True [[ERROR 1]]
    End Sub

    Property ConstruireEstAutorisé() As Boolean
        Get
            Return monConstruireEstAutorisé
        End Get
        Private Set(ByVal value As Boolean)
            Try
                monAfficheur.ConstruireEstAutorisé = value
            Catch ex As Exception
                Throw ex
            End Try
            monConstruireEstAutorisé = value
        End Set
    End Property
[...] 
asked by bb (1.3k points)

20 Answers

0 votes
Applied the fix, works lika a charm!

Thanks for your timely help, Scott. Keep up the excellent work, TypeMock is helping us in a big way!

/C
answered by chibbe (220 points)
0 votes
This has been fixed in version 3.1
answered by scott (32k points)
0 votes
Hi there,

we are trying to get typemock working with 2.0. The problem we have is that we have tried 3.1, but it breaks a whole slew of tests and 3.5.1 fares same/worse. 3.0.3 is the golden build that drives all tests... in 1.1

In 2.0 we get the mentioned BadImageFormatException.

The problem is getting time for issueresolution work in getting our testsuite working with 3.1 or 3.5.1.

Is there any way to get the patch that just solves that issue in 3.0.3?


Best regards,

/marcus
answered by mawi (2k points)
0 votes
Marcus,
Could you please send an example that fails with 3.5.1
We would be more then happy to solve those issues.
answered by scott (32k points)
0 votes
FYI: Im taking the plunge and trying to migrate to 3.5.1.

Eight of our tests go red, all with the same basic issue; the typeloader says its having problems finding an assembly (or deps) with name "gobbledigook.dll".

Example:

XXXX.VBDotNetClientFrameworkIntegrationTests.BusinessService_Live.CacheIsCreated : XXXX.VBDotNetClientFramework.XXXXFrameworkException :
----> System.IO.FileNotFoundException : File or assembly name u-7bn5bj.dll, or one of its dependencies, was not found.

These tests worked using 3.0.3. Hints appreciated, of course. I will try and see what the pattern and problem is.
answered by mawi (2k points)
0 votes
Please try running the fuslogvw.exe (part of the SDK) to find out where the faulty dll is being searched for.
I don't think this is a TypeMock problem as we don't touch that part at all, but of course I might be mistaken
answered by scott (32k points)
0 votes
Hello Scott,

At first, I agreed with you, but after further examination I am feeling very certain that it is a problem with TypeMock. However, it is not easily reproduced - I am only experiencing it with certain assemblies and I have yet to find what causes it. I am thinking that you guys (knowing what typemock does) might be able to deduce it. Here goes:

The problem has to do with typeloading, and what looks to be shadowcopy - or some mechanism like it.

Problem: When TypeMock.Init has been called, creating a XmlSerializer of types in *certain* assemblies does not work. If TypeMock is not loaded (no init called), everything works fine. I am using an exe to test (in order to isolate):

using System;
using System.Xml.Serialization;
using TypeMock;
using XXXX.Core.Cache.Configuration; // I put "Apa2.MyTestClass" in this ambly

public class Class1
{
   public static void Main()
   {
      MockManager.Init();
      XmlSerializer serializer2 = new XmlSerializer( typeof(Apa2.MyTestClass) );
      MockManager.Verify();
   }
}


This throws the aforementioned FileNotFound exception (see previous message). Commenting MockManager.Init will make the code run through with no hitch. (In order to isolate, the class "MyTestClass" is a dummy with no content whatsoever. The important thing is the assembly it resides in.
)

Looking at whats going on with the binding, a temp dll is created and it seems to try to use it for the MyTestClass type, yet I have not confirmed this. Using filemon I see that the DLL is deleted and subsequently an attempt to open it fails. Fusion gives this pruned looking log:

*** Assembly Binder Log Entry  (7/11/2006 @ 2:20:39 PM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:WINDOWSMicrosoft.NETFramework1.1.4322usion.dll
Running under executable  C:	emp	estsTMProblempaexeinDebugpaexe.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: Where-ref bind. Location = C:DOCUME~1CUSWLOCALS~1Tempppoqjrwk.dll
LOG: Appbase = C:	emp	estsTMProblempaexeinDebug
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : (Unknown).
===

LOG: Processing DEVPATH.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/DOCUME~1/CUSW/LOCALS~1/Temp/ppoqjrwk.dll.
LOG: All probing URLs attempted and failed.


As I said though, here is the rub: This only happens for certain assemblies. I have no idea what makes them special (so far only working with one).

If I reference another type in another assembly, no temp dll is created at all. If I comment out MockManager.Init, no temp dll is created. So typemock seems to either be creating it or be indirectly responsible for that it gets created.

I really hope you guys have an idea of what this is about!

Best regards,

Marcus Widerberg

PS
The assembly has a strong name (not in GAC though). Dunno if that matters.
answered by mawi (2k points)
0 votes
Very strange.
Please run typemock with logging and send the log.
answered by scott (32k points)
0 votes
Hello again,

using the test setup as above and further testing I found the issue.

If the assembly where the type "MyTestClass" resides is signed, you get this issue. Ie, in the assemblyinfo:

[assembly: AssemblyKeyFile("..\..\..\XXXX.core.snk")]


When commenting this line everything works fine.

Another note: When working, the temp DLL is created (perhaps the XmlSerializer temp assembly) and deleted, but there is no failing attempt to read it afterwards, and there is obviously no failed binding attempt logged by fusion.

So, in summary: Code that initializes typemock and then attempts to create an XmlSerializer of a type in another signed assembly causes the typeloader to throw.

Consequently, any testsuites that use the XmlSerializer with signed assemblies will fail, fairly mysteriously.

I will post this to the bugforum for completeness, if people experience the same and search there.

Best regards,

/marcus
answered by mawi (2k points)
0 votes
Marcus
Thanks for posting the detailed scenario, this will surly help us fix this.
:twisted: I will reply in the Bug Forum with the solution.
answered by scott (32k points)
...