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:)
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();
}
}
}
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)
This can also be resolved by adding RouteConfig.cs class in your App_Start folder You may be missing the cs file there
I added using System.Web.Routing;
to my code, and worked for me!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With