Asp.Net C#: Upgrading Website to Latest Version Gotchas and How to Resolve

iStock_000015438998XSmallOne can get lost in the weeds when upgrading an .Net 1 website to anything from .Net 2 through .Net 4.  One of the biggest problems after the initial conversion is that when built each page or control throws a build error:

Could not load type ‘MyNamespace.myWebPage’.

The issue stems from the fact that things changed, made life easier for new projects, and namespaces which were required were removed and certain attributes changed. To resolve the above issue follow these steps presented in this article.

In the code behind file

  1. Remove the namespace scope. In the example below remove the highlighted lines:
    namespace MyNamespace
        public class myWebPage : System.Web.UI.Page {}
  2. Add the modifier partial to the class definition to make it look like this
    public partial class myWebPage : System.Web.UI.Page { ... }

In the aspx File

Which initially looks like this:

<%@ Page language="c#" AutoEventWireup="false"
                       Inherits="MyNamespace.myWebPage" %>
  1. Change the attribute Codebehind to CodeFile.
  2. Remove the namespace from the value found in the attribute Inherits.

The result should look like this:

<%@ Page language="c#" AutoEventWireup="false"
                       Inherits="myWebPage" %>


  1. Clinton Gallagher @virtualCableTV says:

    Thanks your tidbits could not be more timely as I’ve dug myself into an upgrade hole after winning Telerik’s RadControls and trying to upgrade a WebForms Web SIte to the latest release of Ajax Control ToolKit.

    I hope you might have the time to respond to how to upgrade the following:

    System.Core, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSI
    System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL

    To Version 4.0 in the gac:

    System.Core, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL
    System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL

    I know how to use gacutil but System.Core and System.Web.Extensions are apparently namespaces in the framework that is updated to 4.0 on this dev machine.

    Finally, the new Web Site template using 4.0 targeting generates the Page directive as AutoEventWireup=”true” noting the use of “false” implies going back to the default coding of 1.0 does it not?

    Thanks for any time you might have to think this over…

  2. Clinton Gallagher @virtualCableTV says:

    Made a new Web Site and dragged Telerik Controls into the Designer. System.Core and System.Web.Extensions now show up in the gac.

    The web.config of my malfunctioning Web Site also contains the updated entries but will only load without error with Cassini still complaining when I run using IIS:

    Could not load file or assembly ‘Telerik.Web.Design’ or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

    Why doesn’t Microsoft try to do what can be done to automate upgrading their own libraries?

Leave a Reply