4

I just had to downgrade my ASP.Net 4.5.2 application to ASP.Net 4.0. Of course this brings problems with it, like references that are not installed correct. I solved some of them already, but I can't get my head around an error:

CS106 'RouteCollection' does not contain a definition for 'MapMvcAttributeRoutes' and no extension method 'MapMvcAttributeRoutes' accepting a first argument of type 'RouteCollection' could be found

public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes) {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapMvcAttributeRoutes();

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "device", action = "view", id = UrlParameter.Optional });
        }
    }

Does someone know what I have to do here?

Extra info

Namespaces that I use:

  • using System.Web
  • using System.Web.Mvc
  • using System.Web.Routing
  • using System.Web.Http

Visual studio Community 2015

NightOwl888
  • 55,572
  • 24
  • 139
  • 212
M Zeinstra
  • 1,931
  • 4
  • 17
  • 46

2 Answers2

6

The only version of MVC that supports attribute routing (which provides support for the MapMvcAttributeRoutes extension method) is MVC 5.

However, MVC 5 only supports .NET framework 4.5 and higher.

So, you have 2 options:

  1. Stay on .NET Framework 4.5+
  2. Downgrade to MVC 4 and either:
    1. Ditch attribute routing altogether and use convention-based routing
    2. Go with the open source attribute routing that supported MVC 3 and 4

Being that Microsoft officially no longer supports any version of .NET Framework lower than 4.5.2 (except for 3.5, but that would mean downgrading to MVC 2 for support), I would highly recommend you consider the first option seriously.

Community
  • 1
  • 1
NightOwl888
  • 55,572
  • 24
  • 139
  • 212
  • Thank you so much for your answer :) May I refer you to a previous question from me? http://stackoverflow.com/questions/37968029/missing-namespaces-when-downgrading-to-asp-net-4-0 – M Zeinstra Jun 23 '16 at 14:08
0

I used routes.Ignore(). It seems to be working.

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes) {
        routes.Ignore("{resource}.axd/{*pathInfo}");

        routes.MapMvcAttributeRoutes();

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "device", action = "view", id = UrlParameter.Optional });
    }
}
prisar
  • 3,041
  • 2
  • 26
  • 27