Aindriú
Aindriú

Reputation: 3740

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

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

Upvotes: 6

Views: 16746

Answers (3)

Hamid
Hamid

Reputation: 1563

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

Upvotes: 2

Kamran
Kamran

Reputation: 371

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

Upvotes: 4

Jesse Webb
Jesse Webb

Reputation: 45283

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)

Upvotes: 6

Related Questions