Friday, February 13, 2009

MSTest error: The location of the file or directory 'log4net.dll' is not trusted.

Today, I upgraded to the latest version of log4net. All my code worked fine, but my unit tests were simply not running. The unit tests were not failing - MSTest was failing to actually run any unit tests. Clicking on the test details led to the following error message:

Failed to queue test run '[test data]': Test Run deployment issue: The location of the file or directory '[path]\log4net.dll' is not trusted.

I did a little research and it turns out Vista has a feature that doesn't allow DLLs to load in certain situations. The strange thing is that my application ran with no problem, but MSTest did not. The solution I found was to unblock the DLL using the file properties dialog.

Unfortunately, no matter how many times I clicked the 'Unblock' button, it just didn't seem to take.

I'm not exactly sure what the true nature of the problem was, but I think it had to do with the fact the DLL was now under source control. I deleted the DLL, got the latest version (the one I had just checked in) from TFS source control. TFS is still a little clunky to me. A simple 'Get Latest' did not work. I had to use the 'Get Specific Version' option and had to use the option to 'Overwrite all files even if the local version matches the specified version', even thought I had deleted the DLL.
At this point I checked out the DLL and used the properties dialog to 'Unblock' the file. This time it worked, and all my tests ran again.

I find it odd that MSTest was not able to load the DLL, but my application ran fine. I guess MSTest is running in some sort of partial trust mode, but I really don't know.

I also find it hard to believe that I've download and installed so many things and this is the first time I've had to 'Unblock' a DLL.

I hope this saves some time for anyone else that has this problem.