views:

55

answers:

2

When running a unittest, I receive the following Exception:

Test method threw exception: System.MissingMethodException: Method not found: 'System.String DataUtilities.HelperMethods.Serialize(!!0)'..

This only happens when running the unittest and not when debugging it. When I debug it, no error occurs.

The signature of the method that is called:

public static string Serialize<T>(T value)

The method is in a referenced dll.

I noticed the following: In the referenced dll there is a method that wraps the call to the Serialize(T value) method.

Its code is:

public static string SerializeList(List<object> list)
{
    TraceClass.Write("something",list);
    string x = HelperClass.Serialize<List<object>>(list);
    TraceClass.Write(x);
    return x;
}

If I call the HelperClass.Serialize using this "indirection" it works fine. In debug and normal run mode.

What am I doing wrong?

+1  A: 

I would check to make sure the dll isn't being referenced from some other location when you're running your unit tests. You most likely have an old dll file sitting around somewhere that is being found by the test runner, and that is why you're getting that error.

Joseph
That was my initial idea also. But: The date of the referenced dll in the out folder of the unittest is current. It would have to be cached somewhere. But why only for debugging?
StampedeXV
@Stampede I'm not sure to be honest. Maybe it's in the GAC or some other project folder?
Joseph
To be in the GAC I would have to add it manually afaik, right? I never did that. I'm really sure of that.I read in some forum that it could be in the IDE folder of Visual Studio, but I couldn't find it there neither.
StampedeXV
@Stampede yeah you'd have to add it knowingly. Sounds like the clean worked, so wherever the old dll was the clean must have found it and refreshed it with the latest.
Joseph
+1 as you were generally right and made me pursue that idea even more fervently
StampedeXV
A: 

Ok. I honestly don't really know what made it worke now, but it's running now.

I deleted all bin and object folders of all directly referenced projects. All intermediate folders used to create the folderstructure needed for the test. All old Testresult folders.

Then rebuild all.

Now it works.

Before, I already did that with all assemblies that were concerned. Obviously it was not enough.

StampedeXV