Converting to VS 2005 and .NET 2.0

 

Converting to .Net 2.0

Overall, the 2.0 conversion should be largely without major issues for most projects. Class libraries, for the most part, convert over and compile without issue. The largest changes are to Web Projects, so that’s where I’ll concentrate this document. I’ll also cover some of the more important warnings that crop up after conversion and actually require work to change.

 

Start here, this is an overview of how Web Projects have changed in .Net 2.0—this is the single largest change that will immediately affect you on a daily basis.

VS 2005 Web Project System: What is it and why did we do it?

 

Step by step guide to converting web projects from VS.Net 2002/2003 to VS 2005

Common Conversion Issues and Solutions (This one is particularly helpful in explaining some of the pitfalls that may arise during further development. It’s important, for instance, to note the new rules on ASCX codebehinds referencing other user controls, as well as non-user control code referencing user controls.)

 

ASP.Net Migration Resources

 

You will also want to read the VS 2005 sections in the Newbie guide—the second section in particular has a number of tips for being more productive in the new IDE.

 

Some recommendations before you convert any Web Application Projects to 2.0:

  • Download and install the update to the Web Project Conversion Wizard. This will avoid at least some of the headaches caused by the original conversion wizard.
  • Load the project file in VS 2003. If the project excludes any files, and you want those files to continue to be excluded after the upgrade, remove them from the disk (and possibly move them to a different location in source control). Otherwise they will be included after the upgrade, causing potential headaches.
  • If your application generates any kind of files that you don’t want stored in source control, and you use the IDE’s source control handling, make sure those generated files are produced outside the Web Project’s folder tree, otherwise VS will want to check them into source control.

 

Major pitfalls and Common warnings post-conversion

Exception Handling

Previously, in .Net 1.x, it was possible to throw a type that did not derive from Exception (e.g. “throw 2” or “throw new object()”). To catch these exceptions, you had to use a catch with empty parentheses (“catch () {…}”). FxCop enforced placing these clauses after any catch clause that caught all Exception objects (since the apparent intent was to catch any throwable). You can still throw non-Exceptions in 2.0, however the runtime will wrap any such inside a RuntimeWrappedException – so the previously required catch() clause is not only unnecessary, it actually causes a compiler warning (since it’s dead code). Fortunately it’s easy to remove, if tedious.

 

XML Transform changes

Microsoft has changed the way XSL transforms work in 2.0; they are now pushing the use of XslCompiledTransform instead. The largest change here is that the XslTransform used “evidence” to decide if certain capabilities should be enabled (the document() function in particular), while the 2.0 counterpart discards evidence in favor of directly setting whether these capabilities should be enabled.

 

Programmatic Code Compilation

If your code performs any compilation on its own (e.g. to enable user-supplied extensions etc), you’ll need to note that the System.CodeDom.Compiler.CodeDomProvider.CreateCompiler() method and its related objects (such as CompilerErrors) are obsolete. Our current code continues to use the obsolete methods, but moving forward we will need to identify the replacement and put it into use.

 

Web Project Validation

You may note that in the new precompiled model, VS 2005 performs a lot more validation of web code. The compiler will verify that referenced files (including controls, images, stylesheets, and javascripts referenced from either an ascx or aspx file) exist, and will flag any missing files as errors. It will also validate your code against one of several standards models, including IE 6, XHTML, etc. You can turn off some of this validation in Tools > Options. This can come into play if your project previously had excluded files (because they were obsolete or not used) or if a reference is just mistyped.

 

Client Side Script Changes

The functions for registering and interacting with client side script have been obsoleted on the Page object, and have been moved to the Page.ClientScript object. Many of these changes are easy (just add .ClientScript before the function name), but in several cases additional arguments (mostly a Type to disambiguate multiple controls trying to add scripts with the same name) have been added.

 

Class Name Collisions

VS 2005 does a lot less “assuming” about class name collisions. In some cases you may need to alias or fully qualify a type name; this may include adding the global:: namespace to a type reference in order to disambiguate a namespace that matches a nested namespace. (For instance, if you are currently in the namespace MyNamespace and there is a nested namespace MyNamespace.System.Text, a reference to the StringBuilder class would need to use global::System.Text.StringBuilder.) Generally the compiler will warn you of any ambiguities.

 

AutoEventWireup

If you encounter a page or control where events do not appear to be firing as expected, add AutoEventWireup=”true” to the @Page or @Control directive, or (probably preferred) use VS 2005 to make sure the events are properly hooked (use the Event pane of the Properties tab for the control). In some cases, the converted code does not properly hook up events and the handlers are never called.

 

IIS Mapping

If you receive the following error, you can fix it by opening your Web Project’s solution in VS 2005 and selecting “Yes” when prompted to overwrite. You may also be able to fix it by opening the IIS Admin panel and using the virtual directory’s ASP.Net tab (on the Properties pane) to set the mapping to 2.0.

 

The issue is that your virtual directory is still linked to ASP.Net 1.1 and it doesn’t understand the new options.

Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Unrecognized configuration section 'xhtmlConformance'
Source Error:
Line 130:                  <xhtmlConformance mode="Legacy"/>