woensdag 5 augustus 2009

A new beginning

Tomorrow (6th of august) Windows 7 will be available to MSDN subscribers, which I am. Hooray! I'm already running the RC and I have to say it is great. I'm going to work with the RC until it expires. But probably on my home pc I will change the OS from Vista to Seven!

dinsdag 4 augustus 2009

Strong name validation failed

Today I faced a problem which took me way too long to solve. I had a project which I wanted to unit test with Visual Studio 2008 and MS Test. As a good developer I sign my assemblies with a snk file.

I created a test project and the necessary unit tests. When I ran the unit test in debug mode the passed (well…the one that were implemented). But when I ran the test without debugging they all failed! Because it was not possible for me to track the thrown exception during a normal test run (due to a WCF service which thrown a totally different exception) I had to add some logging in between to trap the exception in a .txt file.

The exception thrown was:

System.IO.FileLoadException: Could not load file or assembly ‘xxxxxx’ or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)

File name: ‘xxxxxx’ ---> System.Security.SecurityException: Strong name validation failed. (Exception from HRESULT: 0x8013141A)

Weird…I did sign the assembly. And yes when I looked at the project properties the assembly was indeed signed.

image

When I tried to add the assembly of the bin/debug folder of the project to the GAC it succeeded. So it really was signed, else no GAC! For each test run Visual Studio creates a directory TestResults\timg_TIMG01 2009-08-04 19_41_49 (or something similar)

When I tried to add the wretched assembly from the Out directory of the test directory to the GAC I got the folowing error.

Failure adding assembly to the cache: Strong name signature could not be verified. Was the assembly built delay-signed?

No it is not! After that I used the following sn command:

sn –v MyProject.dll

MyProject.dll is a delay-signed or test-signed assembly

How come? I really did sign the assembly! Few frustration later I called a colleague of me who already did much more with MS Test then me. He told me that I had to see if I had enabled code coverage for the assembly. Indeed I had turned on code coverage for my assembly. When I opened the windows I already saw what was going wrong.

image

I had to define my snk file also here or I could turn of code coverage. Took me way too long to solve this problem but again a lesson learned!