can I upgrade my system.web.mvc from 4.5 to 5.0

iqworks Information Quality Works 236 Reputation points
2024-04-25T21:44:22.7566667+00:00

Hi, I have a couple of related threads about this out there, but it is cluttered, so i created this one

I am initially using vs2019.

I have an MVC project called Mbsa. It is my primary project. I am using the runtime version v4.0.3.319. It uses .net framework 4.7.2. It uses system.web.mvc version 4.0.0.1.

My other project is called MBSAnalysisMVCWebApp. It is a web app with a runtime version of v4.0.30319. It uses system.web.mvc 5.2.7.0.

Mbsa references MBSAnalysisMVCWebApp. This is because I want to make a call from my Mbsa controller method to a controller method in MBSAnalysisMVCWebApp.

I am getting this error :

Found conflicts between different versions of "System.Web.Optimization" that could not be resolved.

There was a conflict between "System.Web.Optimization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" and "System.Web.Optimization, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35".

***"System.Web.Optimization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" was chosen because it was primary and "System.Web.Optimization, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" was not.***

***References which depend on "System.Web.Optimization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" [D:\MBSSys\Mbsa\Mbsa 2021\bin\System.Web.Optimization.dll].***

    ***D:\MBSSys\Mbsa\Mbsa 2021\bin\System.Web.Optimization.dll***

      ***Project file item includes which caused reference "D:\MBSSys\Mbsa\Mbsa 2021\bin\System.Web.Optimization.dll".***

        ***System.Web.Optimization***

        ***MbsaBlazorServerSideEF***

        ***MbsaDotNetStandard, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL***

    ***D:\MBSSys\MbsaBlazorServerSideEF\bin\Debug\net6.0\MyBodyScienceAnalysis.dll***

      ***Project file item includes which caused reference "D:\MBSSys\MbsaBlazorServerSideEF\bin\Debug\net6.0\MyBodyScienceAnalysis.dll".***

        ***MbsaBlazorServerSideEF***

        ***MbsaDotNetStandard, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL***

***References which depend on "System.Web.Optimization, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" [].***

    ***D:\MBSSys\MBSAnalysisMVCWebApp\obj\Debug\MBSAnalysisMVCWebApp.dll***

      ***Project file item includes which caused reference "D:\MBSSys\MBSAnalysisMVCWebApp\obj\Debug\MBSAnalysisMVCWebApp.dll".***

        ***MBSAnalysisMVCWebApp	Mbsa***			
```I believe I need to somehow add the system.web.mvc.dll 5.2.7.0 to Mbsa? But my visual studio GAC only has 4.0.0.0 dll's primarily. 

I looked at installing it from tools/nuget manager. But system.web.mvc.dll 5.2.7.0 is not in the nuget manager? I also looked at just installing it in the

In vs2019, I entered this command : PM>   
find-package   
I did not see any system.web.mvc package.

SO, at this point I am wondering :  
1 - Can I install this system.web.mvc 5.2.7.0 to my Mbsa project?  
2 - Am I looking at this situation correctly?

thanks for any advice or suggestions

  

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,189 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,272 questions
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 48,581 Reputation points
    2024-04-25T22:09:20.6833333+00:00

    Yes you can upgrade a project from MVC 4 to MVC 5.2.7. MVC 4 was shipped as part of the framework. All of MVC 5 ships as Nuget packages and have to be explicitly added to your list of packages (which is what the project template does for you).

    You cannot simply call a controller contained in one web project from another one, in general. MVC requires all controllers to be registered up front and that is handled by the runtime scanning your assemblies for controllers. Normally it only looks in the web project assembly but you can override this convention. Nevertheless all the web project code needs to run in the same process so you cannot have 1 set of controllers relying on a different version of MVC (or any assembly) as another. They will all use the same version and whether it works or not depends on what you're doing. Nevertheless it is fragile and not recommended at all.

    In general you should just upgrade your existing MVC 4 project to MVC 5. If that isn't an option then copy all your MVC 4-based code into your MVC 5 project. You do not want to try to host both at the same time.

    If your code base is so huge that you simply cannot migrate everything at once then the alterative is to use YARP from Microsoft to proxy calls from one web app hosted in MVC 4 to the other web app hosted in the newer runtime. However I don't think YARP works for MVC 5, I think it has to be on ASP.NET Core, but I could be wrong. Irrelevant requests that come in to your new app that are not mapped to the newer routes are forwarded to the old app. There are lots of things to consider when doing this and MS has several good writeups on using YARP that you should read. This is the recommended upgrade path if you need both apps running.

    Another alternative is to run the Upgrade Assistant and migrate your app to ASP.NET Core. It unfortunately won't migrate most things but it uses YARP to proxy back to your existing app (which has to be hosted separately). But I'm not sure if it works with MVC 4 which dropped support a while back. It might require MVC 5 before remotely considering upgrading.

    If it were me I'd either just move all the functionality into the MVC 5 project and forget the MVC 4 one or just bite the bullet and switch to ASP.NET Core (bigger effort). If you really, really need to have your MVC 5 project "call into" MVC 4 then the better approach would be to move all that logic that isn't tied to the controller aspect into reusable types (services and whatnot) and then simply have your new controller call into the service type instead of calling the old controller that then calls into the service type. This eliminates the need for "cross controller" calls since a controller should really just handle input/output formatting and passing the real work on to backend components that don't really care about controllers.


0 additional answers

Sort by: Most helpful