asp.net-mvc GlobalConfiguration 不包含 Configure 的定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25450105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
GlobalConfiguration does not contain a definition for Configure
提问by Kirk
I'm attempting to create an ASP.NET MVC site that uses Database First Entity Framework.
我正在尝试创建一个使用 Database First Entity Framework 的 ASP.NET MVC 站点。
I'm using creating a new MVC 5 site in Visual Studio Professional 2013 Update 3, then adding an ADO.NET Entity Data Modelfrom which I choose EF Designer from database.
我正在使用在Visual Studio Professional 2013 Update 3 中创建一个新的 MVC 5 站点,然后添加一个ADO.NET 实体数据模型,我从中选择EF Designer from database。
After that, I create a connection string, select the tables to generate the framework, and all is well.
之后,我创建了一个连接字符串,选择了表来生成框架,一切都很好。
However when I compile it, I receive this error
但是,当我编译它时,我收到此错误
'MyModel.GlobalConfiguration' does not contain a definition for 'Configure'
“MyModel.GlobalConfiguration”不包含“Configure”的定义
This is in Global.asax.csand errors here
这是在Global.asax.cs和这里的错误
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
GlobalConfigurationis automatically generated with the added entity framework for MyModel. It certainly doesn't have a Configure method.
GlobalConfiguration是使用添加的实体框架自动生成的MyModel。它当然没有 Configure 方法。
public partial class GlobalConfiguration
{
public int ID { get; set; }
public long CurrentUSN { get; set; }
public string DBVersion { get; set; }
public long CurrentFile { get; set; }
}
I followed all of the answers here GlobalConfiguration.Configure() not present after Web API 2 and .NET 4.5.1 migrationbut none worked. It's a slightly different situation as this isn't an upgrade but is instead a clean project.
在 Web API 2 和 .NET 4.5.1 迁移之后,我遵循了此处GlobalConfiguration.Configure() 不存在的所有答案,但都没有奏效。这是一个稍微不同的情况,因为这不是升级而是一个干净的项目。
All Extensions and NuGet packages are up to date. I've even deleted the generated entity and reinstalled all NuGet packages to see if that helped, but no luck.
所有扩展和 NuGet 包都是最新的。我什至删除了生成的实体并重新安装了所有 NuGet 包,看看是否有帮助,但没有运气。
Any suggestions?
有什么建议?
回答by Jason Williams
- Open the
Package Manager Consolefor the Project with the error. - Type in
Install-Package Microsoft.AspNet.WebApi.WebHostand hit Enter. - Rebuild your Project.
- 打开
Package Manager Console出现错误的项目。 - 键入
Install-Package Microsoft.AspNet.WebApi.WebHost并按Enter键。 - 重建您的项目。
回答by Kirk
It looks like there is some sort of namespace conflict with the generated code. I'm fairly weary about this change, but everything has worked thus far.
看起来与生成的代码存在某种命名空间冲突。我对这种变化感到相当厌倦,但到目前为止一切都奏效了。
Apparently GlobalConfigurationrefers to MyModel.GlobalConfiguration.
显然GlobalConfiguration是指MyModel.GlobalConfiguration。
However it's really looking for System.Web.Http.GlobalConfiguration
然而它真的在寻找 System.Web.Http.GlobalConfiguration
I switched this and all is working. What a hassle
我切换了这个,一切正常。真麻烦
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
System.Web.Http.GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
回答by Melqui Franco
1 - Make sure the files in your Team Explorer, if perform checkin;
1 - 如果执行签入,请确保您的团队资源管理器中的文件;
2 - Check for old files in "packages" concerning the dll WebAPI such as the folder "Microsoft.AspNet.WebApi.WebHost.5.2.3" folder, if there are clear;
2 - 检查“包”中有关 dll WebAPI 的旧文件,例如文件夹“Microsoft.AspNet.WebApi.WebHost.5.2.3”文件夹,如果有清除;
3 - After leaving everything clean install the project;
3 - 一切都干净后安装项目;
Good luck!!!!!
祝你好运!!!!!

