2

I am a beginner to .NET. And I have looked at the several other posts with similar titles asked before. I tried these suggestions (As described below) but didn't help.

I need to use a project built by someone else to test a functionality.

When I build the project I get these two errors.

Severity Code Description Project File Line Suppression State Error CS1061 'RouteCollection' does not contain a definition for 'IgnoreRoute' and no accessible extension method 'IgnoreRoute' accepting a first argument of type 'RouteCollection' could be found

.

Severity Code Description Project File Line Suppression State Error CS1061 'RouteCollection' does not contain a definition for 'MapRoute' and no accessible extension method 'MapRoute' accepting a first argument of type 'RouteCollection' could be found

The offending code is this.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

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

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

First I read this post. RouteCollection' doesn't contain a definition for 'MapMvcAttributeRoutes

The most voted answer states that this is because it requires .NET version 4.5+ and the OP has 4.0 something.

Next I wanted to check the .NET version installed in my machine. In developer command prompt

clrver

Microsoft (R) .NET CLR Version Tool  Version 4.6.1055.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Versions installed on the machine:
v4.0.30319

It seems I have an 4.0 version.

But when I try to install .NET 4.5.2 I get this error.

enter image description here

I ran the .NET Framework verification utility and it says that 4.5.2 is installed properly.

enter image description here

Project target framework is set to 4.5.2

enter image description here

This post suggests that this might be because of Resharper plugin. MapRoute and IgnoreRoute Up and Vanished RSS

So, I disabled resharper but the errors were still there.

EDITS Screenshots show when I tried installing 4.5.2 version of .NET

Enzio
  • 799
  • 13
  • 32
  • https://stackoverflow.com/questions/38850322/routecollection-doesnt-contain-a-definition-for-mapmvcattributeroutes – Salah Akbari Oct 24 '18 at 10:01
  • @S.Akbari I did check this post earlier. The OP himself has given the answer and haven't given any explanation for what he did. And I'm bit hesitant to change the code unless I understand why. Also the project did work successfully when I tested on a mac yesterday. (With Resharper IDE) – Enzio Oct 24 '18 at 10:11
  • You are showing Net 4.5.2 while the Project is set to 4.7.2. Not all Net libraries are part of each version of Net. You need to have all previous version installed to make sure you have all the libraries. The link S.Akbari provided the OP installed Net 4.5.2 using the link on the posting. I think you should install Net 4.5.2. – jdweng Oct 24 '18 at 10:28
  • @jdweng 4.5.2 is already installed. I checked with verifier tool. Sorry for the wrong screenshot above. I'll update the question. – Enzio Oct 24 '18 at 10:34
  • Is Net 3.5 installed? I went to Microsoft Reference which has the source code for the c# and it looks like IgnoreRoute is part of Net 3.5. – jdweng Oct 24 '18 at 10:40
  • @jdweng It was not installed. But I installed it now. Does't seems to make any difference. https://imgur.com/a/Av0tqTM – Enzio Oct 24 '18 at 10:50
  • See msdn blog : https://blogs.msdn.microsoft.com/webdev/2013/10/17/attribute-routing-in-asp-net-mvc-5/ – jdweng Oct 24 '18 at 10:57

0 Answers0