Is it possible to upgrade my system.web.mvc 4.0.0.1 to mvc 5.7.2.0

iqworks Information Quality Works 216 Reputation points
2024-04-17T21:12:23.4233333+00:00

I have an MVC 4.7.2. It uses system.web.mvc 4.0.0.1. I have another project that is 4.7.2 that uses system.web.mvc 5.2.7.0..But when I reference 5.2.7.0, I get an error :

 

Assembly 'MBSAnalysisMVCWebApp' with identity 'MBSAnalysisMVCWebApp, Version=2024.3.11.0, Culture=neutral, PublicKeyToken=null' uses 'System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Mvc' with identity 'System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

 

  I am having problems with this :

 

PS D:\MBSSys\Mbsa\Mbsa 2021> dotnet add package Microsoft.AspNet.Mvc --version 5.2.7 D:\MBSSys\Mbsa\Mbsa 2021\Mbsa.csproj(4234,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\8.0 .200\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that th e expression in the Import declaration "C:\Program Files\dotnet\sdk\8.0.200\Microsoft\VisualStudio\v16.0\WebApplic ations\Microsoft.WebApplication.targets" is correct, and that the file exists on disk. Unable to create dependency graph file for project 'D:\MBSSys\Mbsa\Mbsa 2021\Mbsa.csproj'. Cannot add package refer ence. PS D:\MBSSys\Mbsa\Mbsa 2021>

Is it possible to upgrade my system.web.mvc 4.0.0.1 to mvc 5.7.2.0? or am I asking for trouble?

 

Thanks for any advice or suggestions

 

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,263 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 56,286 Reputation points
    2024-04-17T21:54:40.9766667+00:00

    you 4.7.2 project probably references another project that uses a lower version of the MVC nuget packages. you should probably update all projects to the current version 5.3.0. if you can not upgrade than in the web.config use assembly bind to redirect older versions to current:

     <!-- use System.Web.Mvc 5.3.0 -->
     <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-5.3.0.0" newVersion="5.3.0.0" />
     </dependentAssembly>
    

    https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/redirect-assembly-versions

    you second issue is that the nuget package Microsoft.AspNet.Mvc, which is .net 4.* based, can not be used with a .net core application. .net core has its own MVC package which is part of the Microsoft.NET.Sdk.Web sdk, and not a seperate nuget package.

    simple .net 8 MVC project file (note sdk used):

    <Project Sdk="Microsoft.NET.Sdk.Web">
      <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
      </PropertyGroup>
    </Project>