Thursday, February 21, 2013

Upgrading from .Net 3.5 to 4.0

I'm upgrading an old ASP.Net app from .Net 3.5 to 4.0.  Here were some of my issues:
1.  Compile error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)
This is error is from the build machine using the old 3.5 libraries.  We have to tell it to use the 4.0 libraries in nant.  I added this to my nant build script:
<property name="nant.settings.currentframework" value="net-4.0" />

2. The automatic upgrade did not switch all the versions, I had to manually change the version number for many of my projects from:
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C5619000000"/>
to:
<add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C5619000000"/>

3.  Menu Items from Web.sitemap disappered
The orginal code looked like this:
if (SiteMap.CurrentNode != null && SiteMap.CurrentNode.IsDescendantOf(node))
                {
                    Repeater repeater = (Repeater)e.Item.FindControl("repeaterBar");
                    repeater.DataSource = node.ChildNodes;
                    repeater.DataBind();
                }

I added one new condition to see if the current node was the node:
                if ((SiteMap.CurrentNode != null)
                     && (SiteMap.CurrentNode.IsDescendantOf(node) ||
                    SiteMap.CurrentNode == node))
                {
                    Repeater repeater = (Repeater)e.Item.FindControl("repeaterBar");
                    repeater.DataSource = node.ChildNodes;
                    repeater.DataBind();
                }
            }
Then it worked like it did in 3.5.

4.  A form submission gave this error:  "A potentially dangerous Request.Form value was detected from the client"
This was fixed by adding  "<httpRuntime requestValidationMode="2.0" />" to the web.config under "<System.Web>"

Overall the upgrade was not too bad.

No comments: