微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

WebApp Azure 发布:我的 db-first WebApp (ASP.NET 4.8) 出现 EF6 模型验证错误

如何解决WebApp Azure 发布:我的 db-first WebApp (ASP.NET 4.8) 出现 EF6 模型验证错误

将最新版本的 WebApp 发布到 Azure 上的暂存槽时,我在发布后立即开始收到以下错误

Server Error in '/' Application.
One or more validation errors were detected during model generation:

CodeFirstNamespace.AspNetUserLogins: : EntityType 'AspNetUserLogins' has no key defined. Define the key for this EntityType.
CodeFirstNamespace.AspNetUserTokens: : EntityType 'AspNetUserTokens' has no key defined. Define the key for this EntityType.
CodeFirstNamespace.companies: : EntityType 'companies' has no key defined. Define the key for this EntityType.

 ....etc etc..

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.Entity.ModelConfiguration.ModelValidationException: One or more validation errors were detected during model generation:

CodeFirstNamespace.AspNetUserLogins: : EntityType 'AspNetUserLogins' has no key defined. Define the key for this EntityType.
CodeFirstNamespace.AspNetUserTokens: : EntityType 'AspNetUserTokens' has no key defined. Define the key for this EntityType.
CodeFirstNamespace.companies: : EntityType 'companies' has no key defined. Define the key for this EntityType.

...等等等等...

Source Error:

An unhandled exception was generated during the execution of the current web request. information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[ModelValidationException: One or more validation errors were detected during model generation:

CodeFirstNamespace.AspNetUserLogins: : EntityType 'AspNetUserLogins' has no key defined. Define the key for this EntityType.
CodeFirstNamespace.AspNetUserTokens: : EntityType 'AspNetUserTokens' has no key defined. Define the key for this EntityType.
CodeFirstNamespace.companies: : EntityType 'companies' has no key defined. Define the key for this EntityType.

   System.Data.Entity.Core.Metadata.Edm.EdmModel.Validate() +432
   System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest,DbProviderInfo providerInfo) +319
   System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) +55
   System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) +159
   System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) +123
   System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +646
   System.Data.Entity.Internal.InternalContext.Initialize() +21
   System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +16
   System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +53
   System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +16
   System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() +38
   System.Linq.Queryable.Where(IQueryable`1 source,Expression`1 predicate) +83
   ims2_App.Utility.CheckRole(ApplicationUser cu,String role) in C:\Users\kenni\source\repos\ims-Azure\ims2_App\Routines\Utility.vb:90
   ims2_App.HomeController.SalesPipeline() in C:\Users\kenni\source\repos\ims-Azure\ims2_App\Controllers\HomeController.vb:250
   lambda_method(Closure,ControllerBase,Object[] ) +66
   System.Web.Mvc.ActionMethoddispatcher.Execute(ControllerBase controller,Object[] parameters) +19
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext,IDictionary`2 parameters) +169
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext,ActionDescriptor actionDescriptor,IDictionary`2 parameters) +27
   System.Web.Mvc.Async.<>c.<BeginInvokeSynchronousActionMethod>b__9_0(IAsyncResult asyncResult,ActionInvocation innerInvokeState) +24
   System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +31
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +50
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +33
   System.Web.Mvc.Async.<>c__displayClass11_0.<InvokeActionMethodFilterasynchronouslyRecursive>b__0() +58
   System.Web.Mvc.Async.<>c__displayClass11_2.<InvokeActionMethodFilterasynchronouslyRecursive>b__2() +228
   System.Web.Mvc.Async.<>c__displayClass7_0.<BeginInvokeActionMethodWithFilters>b__1(IAsyncResult asyncResult) +15
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +15
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +50
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +35
   System.Web.Mvc.Async.<>c__displayClass3_6.<BeginInvokeAction>b__4() +35
   System.Web.Mvc.Async.<>c__displayClass3_1.<BeginInvokeAction>b__1(IAsyncResult asyncResult) +100
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +15
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +50
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +29
   System.Web.Mvc.<>c.<BeginExecuteCore>b__152_1(IAsyncResult asyncResult,ExecuteCoreState innerState) +13
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +50
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +45
   System.Web.Mvc.<>c.<BeginExecute>b__151_2(IAsyncResult asyncResult,Controller controller) +15
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +50
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +27
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +12
   System.Web.Mvc.<>c.<BeginProcessRequest>b__20_1(IAsyncResult asyncResult,ProcessRequestState innerState) +28
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +50
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +29
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +11
   System.Web.Mvc.<>c__displayClass3_0.<EndProcessRequest>b__0() +24
   System.Web.Mvc.<>c__displayClass5_0.<Wrap>b__0() +15
   System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Func`1 func) +27
   System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Action action) +64
   System.Web.Mvc.ServerExecuteHttpHandlerAsyncWrapper.EndProcessRequest(IAsyncResult result) +71
   System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler,TextWriter writer,Boolean preserveForm,Boolean setPrevIoUsPage,VirtualPath path,VirtualPath filePath,String physPath,Exception error,String queryStringOverride) +1454

[HttpException (0x80004005): Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.]
   System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler,String queryStringOverride) +2363
   System.Web.HttpServerUtility.Execute(IHttpHandler handler,Boolean setPrevIoUsPage) +78
   System.Web.HttpServerUtility.Execute(IHttpHandler handler,Boolean preserveForm) +26
   System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler,Boolean preserveForm) +25
   System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper,String actionName,String controllerName,RouteValueDictionary routeValues,TextWriter textWriter) +466
   System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper,RouteValueDictionary routeValues) +83
   System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper,String actionName) +14
   ASP._Page_Views_Home_Index_vbhtml.Execute() +677
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +105
   System.Web.WebPages.StartPage.RunPage() +19
   System.Web.WebPages.StartPage.ExecutePageHierarchy() +73
   System.Web.WebPages.StartPage.RunPage() +19
   System.Web.WebPages.StartPage.ExecutePageHierarchy() +73
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext,WebPageRenderingBase startPage) +78
   System.Web.Mvc.RazorView.RenderView(ViewContext viewContext,Object instance) +235
   System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext,TextWriter writer) +107
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +291
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext,ActionResult actionResult) +15
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters,Int32 filterIndex,ResultExecutingContext preContext,ControllerContext controllerContext,ActionResult actionResult) +56
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters,ActionResult actionResult) +420
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext,IList`1 filters,ActionResult actionResult) +52
   System.Web.Mvc.Async.<>c__displayClass3_6.<BeginInvokeAction>b__4() +197
   System.Web.Mvc.Async.<>c__displayClass3_1.<BeginInvokeAction>b__1(IAsyncResult asyncResult) +100
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +15
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +50
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +29
   System.Web.Mvc.<>c.<BeginExecuteCore>b__152_1(IAsyncResult asyncResult,ProcessRequestState innerState) +28
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +50
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +29
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +11
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +576
   System.Web.<>c__displayClass285_0.<ExecuteStepImpl>b__0() +26
   System.Web.StepInvoker.Invoke(Action executionStep) +100
   System.Web.<>c__displayClass4_0.<Invoke>b__0() +22
   Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule.OnExecuteRequestStep(HttpContextBase context,Action step) +65
   System.Web.<>c__displayClass284_0.<OnExecuteRequestStep>b__0(Action nextStepAction) +54
   System.Web.StepInvoker.Invoke(Action executionStep) +84
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +100
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously) +163

该应用程序在开发系统和实时系统(使用与暂存槽相同的数据库)上都可以正常工作,并且可以继续正常工作。

查询上下文时,linq 处理程序似乎抛出了异常 - 大概是然后发生了延迟验证并且所有这些异常都被抛出。然而,它们似乎无效,并且代码在 devBox 上运行良好。

发布配置文件替换了各种 .config 文件中的 Azure 连接字符串。

我不知道除了对系统进行了微小的更改之外,我还没有做任何其他事情,并且看到应用程序坚决地以数据库为先,看到“CodeFirstNamespace.”出现在异常中并且 DBModelBuilder 启动时,我感到很震惊。

Azure 是否会在不应该运行的时候尝试运行迁移/初始化程序?

解决方法

解决了。我发现的相当不令人满意的解决方案是删除部署槽并基于此创建新的发布配置文件。

我只能猜测我以某种方式设法使部署槽停了下来 - 尽管查看 pubxml 文件我确实看到了一些差异/额外的字段(尽管没有什么会引起 EF 头痛)。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。