Monday, June 14, 2010

Handling Microsoft’s refactoring between Net3.5 and Net4.0

I have a web server control library (the real stuff, not user controls) that I often include in web sites. While building a 4.0 site,  I encountered:


The type name 'MembershipUser' could not be found. This type has been forwarded to assembly 'System.Web.ApplicationServices, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Consider adding a reference to that assembly. 


Ah! Microsoft has done some refactoring in their class libraries. Wrong, the class libraries are the same, they just moved the dll that it is located in!  In Object Viewer, you will see:

So all that needs to be done is add a reference to this DLL.


I am not happy with how they did it --- it breaks normative conventions…. The DLL. “System.Web.ApplicationServices” does not contain a class called: System.Web.ApplicationServices.

Second,  the two classes in it would be flagged as a misplacement in any respectable code review!


In terms of maintaining one code base that will support .Net2 thru .Net4, it may be done by using two projects:

  • MyProject.Net2.csproj
  • MyProject.Net4.csproj

with the .cs files being shared.  In this case the members of the classes appear unchanged, but if they were changed then I would need to add a C# directive  “NET4”  and conditionally code – still allows me to maintain a single .cs file for each of the control.