Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Global.asax.cs name 'RouteConfig' does not exist in the current context

Tags:

c#

there are three files in my solution which I think I referencing but I am stuck with these 3 errors

Global.asax.cs name 'RouteConfig' does not exist in the current context

What am I missing ? thanks:)

enter image description here

enter image description here

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Web.Http;


namespace PingYourPackage.API.WebHost
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            var config = GlobalConfiguration.Configuration;


            RouteConfig.RegisterRoutes(config);
            WebAPIConfig.Configure(config);
            AutofacWebAPI.Initialize(config);
        }

***************

here is the class autofac

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using Autofac;
using Autofac.Integration.WebApi;
using System.Reflection;


namespace PingYourPackage.Config
{
    public class AutofacWebAPI
    {
        public static void Initialize(HttpConfiguration config)
        {
            Initialize(config,
                RegisterServices(new ContainerBuilder()));
        }

        public static void Initialize (
            HttpConfiguration config, IContainer container)
        {
            config.DependencyResolver =
                new AutofacWebApiDependencyResolver(container);
        }

        private static IContainer RegisterServices(ContainerBuilder builder)
        {
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

            // registeration goes here

            return builder.Build();
        }
    }
}

enter image description here

like image 683
Aindriú Avatar asked Jan 26 '15 20:01

Aindriú


3 Answers

When you generate a new project, these *Config classes (e.g. RouteConfig) are put in App_Code by default.

It looks like you moved the *Config classes out from the App_Code directory, into a Config directory. Everything in App_Code is automatically referenced by other code in your project.

https://msdn.microsoft.com/en-us/library/ex526337(v=vs.140).aspx

Code in the App_Code folder is referenced automatically in your application.

It is okay that you moved them, they can live anywhere. Now, you just need to reference them manually inside your Global.asax.cs file.

using PingYourPackage.Config;

(assuming PingYourPackage is the name of your project/root namespace)

like image 185
Jesse Webb Avatar answered Oct 28 '22 01:10

Jesse Webb


This can also be resolved by adding RouteConfig.cs class in your App_Start folder You may be missing the cs file there

like image 28
Kamran Avatar answered Oct 27 '22 23:10

Kamran


I added using System.Web.Routing; to my code, and worked for me!

like image 24
Hamid Avatar answered Oct 28 '22 01:10

Hamid