Currently I am working on a Unit Test project based on Microsoft Testing Framework for .NET 4.0 which is testing a project based on Silverlight 4.0. So far everything has been fine but today I wrote a test that was exercising the serialization of a class to JSON and ran into the following exception. The class is using System.ServiceModel library and its fields are annotated.
Here is the error I was getting when running the unit test in Visual Studio 2010:
System.IO.FileNotFoundException: Could not load file or assembly 'System.ServiceModel.Web, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
I tried to get both the Project Under Test, and the Test Project to use the same System.ServiceModel library but was not successful. Visual Studio would not allow the Silverlight Project to use the same libraries as the .NET 4.0 Framework and it would also not allow the Unit Test Project to use the same libraries as the Silverlight Project. After trying different options, I found a very hacky solution.
The hacky fix is to specify the reference paths for the Unit Test project. Here is what you need to do: