[RESOLVED]Upgrade from MVC2-3

Hi
I am trying to upgrade my app from MVC 2 ->3, either using tools, or manual. However, when I tried to run my app, I hit error as below. Before upgrade, it is working fine.

The error pointed to ASPX inline code Url.Content(). Any ideas? tq

Edited: After some investigation, found that Url object is null. What cause this happen?

System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=App_Web_1r5z2fif
StackTrace:
at ASP.views_home_logon_aspx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:WorksMyApp V26.0CodeMyAppWebViewsHomeLogOn.aspx:line 10
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.Page.Render(HtmlTextWriter writer)
at System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:

Are you getting this error in the MVC3 or MVC2.

pprasannak

Are you getting this error in the MVC3 or MVC2.

MVC3. working fine in MVC2

Edited: Found that MVC2 hit the same exception now after I installed MVC3. I didnt change anything to MVC2 project. =.=

Hi chanmy8,

Thanks for your post.

According to your description,

chanmy8

Upgrade from MVC2-3

ASP.NET MVC 3 can be installed side by side with ASP.NET MVC 2 on the same computer, which gives you flexibility in choosing when to upgrade an ASP.NET MVC 2 application to ASP.NET MVC 3.

To manually upgrade an existing ASP.NET MVC 2 application to version 3, do the following:

  1. Create a new empty ASP.NET MVC 3 project on your computer. This project will contain some files that are required for the upgrade.
  2. Copy the following files from the ASP.NET MVC 3 project into the corresponding location of your ASP.NET MVC 2 project. You’ll need to update any references to the jQuery library to account for the new filename ( jQuery-1.5.1.js): 
    • /Views/Web.config
    • /packages.config
    • /scripts/*.js
    • /Content/themes/*.*
  3. Copy the packages folder in the root of the empty ASP.NET MVC 3 project solution into the root of your solution, which is in the directory where the solution’s .sln file is located.
  4. If your ASP.NET MVC 2 project contains any areas, copy the /Views/Web.config file to the
    Views folder of each area.
  5. In both Web.config files in the ASP.NET MVC 2 project, globally search and replace the ASP.NET MVC version. Find the following:
    System.Web.Mvc, Version=2.0.0.0

    Replace it with the following:

    System.Web.Mvc, Version=3.0.0.0
  6. In Solution Explorer, delete the reference to System.Web.Mvc (which points to the DLL from version 2), then add a reference to
    System.Web.Mvc (v3.0.0.0).
  7. Add a reference to System.Web.WebPages.dll and System.Web.Helpers.dll. These assemblies are located in the following folders: 
    • %ProgramFiles% Microsoft ASP.NETASP.NET MVC 3Assemblies
    • %ProgramFiles% Microsoft ASP.NETASP.NET Web Pagesv1.0Assemblies
  8. In Solution Explorer, right-click the project name and select Unload Project. Then right-click the project name again and select Edit
    ProjectName.csproj.
  9. Locate the ProjectTypeGuids element and replace {F85E285D-A4E0-4152-9332-AB1D724D3325} with {E53F8FEA-EAE0-44A6-8774-FFD645390401}.
  10. Save the changes, right-click the project, and then select Reload Project.
  11. In the application’s root Web.config file, add the following settings to the
    assemblies
    section.

    <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, 
         PublicKeyToken=31BF3856AD364E35" />
    
    <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral,
         PublicKeyToken=31BF3856AD364E35" />
  12. If the project references any third-party libraries that are compiled using ASP.NET MVC 2, add the following highlighted
    bindingRedirect element to the Web.config file in the application root under the
    configuration section:

    <runtime>
       <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
           <assemblyIdentity name="System.Web.Mvc"
               publicKeyToken="31bf3856ad364e35"/>
           <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0"/>
         </dependentAssembly>
       </assemblyBinding>
    </runtime>

More information,you can refer to the following link:

#Upgrading an ASP.NET MVC 2 Project to ASP.NET MVC 3 Tools Update

http://www.asp.net/whitepapers/mvc3-release-notes#upgrading

Hope this can be helpful.

Best Regards,

Eileen

Leave a Reply