Saturday, February 26, 2011

Could not load file or assembly 'System.ServiceModel.Web, Version=2.0.5.0

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:

Wednesday, February 23, 2011

Object-Oriented Anti-Pattern - Data Objects with Behavior

As software engineers we are all taught about the Object-Oriented (OO) paradigm  and make every effort to design according to OO rules and patterns. Most high level languages go as far as to forbid non-OO programming. Even so, it doesn't take long for any software engineer to tell you about many applications where OO is misused. I think one very good example where OO is misused is with Data Objects.

What is a Data Object?
Data Objects represent data pieces that are grouped together to form a single structure or entity. Two very good examples of Data Objects are ORM Entity Objects and Data Transfer Objects.

Attributes and Behavior
Objects are made up of attributes and behavior but Data Objects by definition represent only data and hence can have only attributes. Books, Movies, Files, even IO Streams do not have behavior. A book has a title but it does not know how to read. A movie has actors but it does not know how to play. A file has content but it does not know how to delete. A stream has content but it does not know how to open/close or stop. These are all examples of Data Objects that have attributes but do not have behavior. As such, they should be treated as dumb data objects and we as software engineers should not force behavior upon them.