代码之家  ›  专栏  ›  技术社区  ›  InteXX

更新EF 6.x后出现意外异常链

  •  0
  • InteXX  · 技术社区  · 5 年前

    我从EF6.2更新到EF6.4,遇到了以下异常链:

    [VerificationException: Operation could destabilize the runtime.]
       System.Data.Entity.Core.Metadata.Edm.FacetDescription.Validate(String declaringTypeName) +70
       System.Data.Entity.Core.Metadata.Edm.FacetDescription..ctor(String facetName, EdmType facetType, Nullable`1 minValue, Nullable`1 maxValue, Object defaultValue, Boolean isConstant, String declaringTypeName) +103
       System.Data.Entity.Core.SchemaObjectModel.FacetDescriptionElement.CreateAndValidateFacetDescription(String declaringTypeName) +115
       System.Data.Entity.Core.SchemaObjectModel.TypeElement.ResolveTopLevelNames() +119
       System.Data.Entity.Core.SchemaObjectModel.Schema.ResolveTopLevelNames() +206
       System.Data.Entity.Core.SchemaObjectModel.Schema.Resolve() +16
       System.Data.Entity.Core.SchemaObjectModel.SchemaManager.ParseAndValidate(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, SchemaDataModelOption dataModel, AttributeValueNotification providerNotification, AttributeValueNotification providerManifestTokenNotification, ProviderManifestNeeded providerManifestNeeded, IList`1& schemaCollection) +554
       System.Data.Entity.Core.SchemaObjectModel.SchemaManager.ParseAndValidate(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, SchemaDataModelOption dataModel, DbProviderManifest providerManifest, IList`1& schemaCollection) +156
       System.Data.Entity.Core.SchemaObjectModel.SchemaManager.LoadProviderManifest(XmlReader xmlReader, String location, Boolean checkForSystemNamespace, Schema& schema) +151
       System.Data.Entity.Core.Common.DbXmlEnabledProviderManifest.Load(XmlReader reader) +75
       System.Data.Entity.Core.Common.DbXmlEnabledProviderManifest..ctor(XmlReader reader) +116
       System.Data.Entity.SqlServer.SqlProviderManifest..ctor(String manifestToken) +37
       System.Data.Entity.SqlServer.<>c.<GetDbProviderManifest>b__29_0(String s) +25
       System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) +65
       System.Data.Entity.SqlServer.SqlProviderServices.GetDbProviderManifest(String versionHint) +125
       System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifest(String manifestToken) +55
    
    [ProviderIncompatibleException: The provider did not return a ProviderManifest instance.]
       System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifest(String manifestToken) +187
       System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest) +119
       System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) +43
       System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) +159
       System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) +124
       System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +678
       System.Data.Entity.Internal.InternalContext.Initialize() +20
       Website.Db.Context..ctor(DbConnection Connection) in Context.vb:15
       Website._Default.GetNewsItems() in Default.aspx.vb:13
    
    [TargetInvocationException: Exception has been thrown by the target of an invocation.]
       System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
       System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +92
       System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +191
       System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +19
       lambda_method(Closure , MethodInfo , Object , Object[] ) +39
       System.Web.UI.WebControls.ModelDataSourceView.InvokeMethod(ModelDataSourceMethod method, Boolean isAsyncMethod) +326
       System.Web.UI.WebControls.ModelDataSourceView.InvokeMethod(ModelDataSourceMethod method) +7
       System.Web.UI.WebControls.ModelDataSourceView.GetSelectMethodResult(DataSourceSelectArguments arguments) +68
       System.Web.UI.WebControls.ModelDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +14
       System.Web.UI.WebControls.Repeater.GetData() +233
       System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +207
       System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +62
       System.Web.UI.WebControls.Repeater.DataBind() +131
       System.Web.UI.WebControls.Repeater.EnsureDataBound() +114
       System.Web.UI.WebControls.Repeater.OnPreRender(EventArgs e) +16
       System.Web.UI.Control.PreRenderRecursiveInternal() +166
       System.Web.UI.Control.PreRenderRecursiveInternal() +236
       System.Web.UI.Control.PreRenderRecursiveInternal() +236
       System.Web.UI.Control.PreRenderRecursiveInternal() +236
       System.Web.UI.Control.PreRenderRecursiveInternal() +236
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4722
    

    这是第15行 Context.vb :

    Database.SetInitializer(New MigrateDatabaseToLatestVersion(Of Context, Migrations.Configuration))
    

    我会说,这是一个非常简单的数据库调用。

    然而,当我跳回到EF6.2时,错误停止了。

    我在SO上发现了很多对单个异常的引用,但到目前为止,我还没有发现任何一个引用完全符合这三者结合在一起的上下文以及代码正在做的事情(通用数据库访问)。

    我是否需要以某种方式更改我的DAL代码以适应EF6.4更新?是否有一些突破性的变化?

    --编辑--

    在Medium Trust的明确设置下本地运行,我得到了一个不同的链:

    [PolicyException: Execution permission cannot be acquired.]
       System.Security.CodeAccessSecurityEngine.TryResolveGrantSet(Evidence evidence, PermissionSet& grantSet) +14092083
       System.Security.CodeAccessSecurityEngine.ResolveGrantSet(Evidence evidence, Int32& specialFlags, Boolean checkExecutionPermission) +60
    
    [FileLoadException: Could not load file or assembly 'Microsoft.WebTools.BrowserLink.Runtime, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. PolicyException thrown. (Exception from HRESULT: 0x80131416)]
       System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
       System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +232
       System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark) +176
       System.Reflection.Assembly.LoadFrom(String assemblyFile) +53
       Microsoft.VisualStudio.Web.PageInspector.Runtime.Loader.RuntimeLoader.GetRuntimeAssemblyFromSetupConfiguration(Assembly& runtime) +27
       Microsoft.VisualStudio.Web.PageInspector.Runtime.Loader.RuntimeLoader.LoadRuntime() +26
       Microsoft.VisualStudio.Web.PageInspector.Runtime.Loader.RuntimeLoader.PreApplicationStart() +45
    
    [InvalidOperationException: The pre-application start initialization method PreApplicationStart on type Microsoft.VisualStudio.Web.PageInspector.Runtime.Loader.RuntimeLoader threw an exception with the following error message: Could not load file or assembly 'Microsoft.WebTools.BrowserLink.Runtime, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. PolicyException thrown. (Exception from HRESULT: 0x80131416).]
       System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +919
       System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +169
       System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +172
       System.Web.Compilation.BuildManager.ExecutePreAppStart() +172
       System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +854
    
    [HttpException (0x80004005): The pre-application start initialization method PreApplicationStart on type Microsoft.VisualStudio.Web.PageInspector.Runtime.Loader.RuntimeLoader threw an exception with the following error message: Could not load file or assembly 'Microsoft.WebTools.BrowserLink.Runtime, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. PolicyException thrown. (Exception from HRESULT: 0x80131416).]
       System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +532
       System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +111
       System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +724
    

    这在EF6.2和EF6.4下都会发生。

    0 回复  |  直到 5 年前
        1
  •  2
  •   Steve Py    5 年前

    如果在升级EF版本后,这种情况发生在远程部署上,而不是本地开发环境中,那么我怀疑部署过程存在问题。

    1. 检查部署的版本中的web.config,以确保没有与EF相关的运行时版本依赖关系版本覆盖。(EntityFramework.dll和EntityFramework.sql服务器.dll)

    2. 检查远程服务器上部署的文件和工作本地实例之间的EntityFramework.dll程序集版本。

    3. 将部署从远程服务器复制到本地文件夹中,将IIS指向该文件夹,然后使用w3wp.exe上的“附加到进程”连接VS运行项目。在代码中的某个地方设置一个断点,并检查它是否仍然是一个“热门”可命中的断点,而不是一个非活动的断点,说明“断点当前不会被命中。源代码行不匹配…”这将表明部署的代码没有反映您在VS中运行的当前完整重建。

    如果您使用的是自动构建:

    1. 请检查是否未签入依赖DLL,以及生成计算机是否正在正确解析NuGet包。

    2. 在升级EF版本之前,请检查EF的引用(源代码管理还原所有更改,使用上次构建和部署的内容)。在项目资源管理器的引用下,选择EntityFramework并检查列出的路径。它应该指向: {您的解决方案文件夹}\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll 如果它指向的是\bin\debug等文件夹,请删除引用并修复以指向NuGet包。

    3. 如果已签入NuGet包文件夹,请确保此文件夹在源代码管理中是完整且最新的。当签入nuget文件夹时(与包版本锁定相反),我发现这需要从Explorer/TFS完成,因为正常的VS签入不会将它们包含在挂起的更改中。(与/bin文件夹更改不同,如果您允许的话。)在进行初始签入时可以跳过包文件夹更新,但随后会添加/更新.ignore文件等内容,导致较新的.dll文件不会更新。

    4. 检查本地环境中与源代码管理中的项目文件(.csproj/.vbproj)是否过时或不匹配。通常,这些文件会在某个时候被标记为“排除的文件”,导致使用过时的引用进行自动构建。

    检查一下这些,看看有没有发现什么。