Unexpected exception chain after updating EF 6.x

entity-framework entity-framework-6

Question

I updated from EF6.2 to EF6.4 and I encountered this exception chain:

[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

Here's line 15 of Context.vb:

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

A pretty straightforward database call, I'd say.

However, when I bumped back down to EF6.2, the error stopped.

I'm finding plenty of references to the individual exceptions here on SO, but nothing I've found so far quite fits the context of the combination of the three taken together with what the code is doing (general database access).

Do I need to alter my DAL code somehow in order to accommodate the EF6.4 update? Were there some breaking changes?

--EDIT--

Running locally under an explicit setting of Medium Trust, I get a different chain:

[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

This occurs under both EF6.2 and EF6.4.

1
0
2/5/2020 4:10:49 AM

Popular Answer

If this is occurring on your remote deployment and not your local development environment after upgrading the EF version then I would suspect there is an issue with the deployment process.

  1. Check the web.config in the deployed build to ensure that there are no EF-related runtime version dependency version overrides. (EntityFramework.dll and EntityFramework.SqlServer.dll)

  2. Check the EntityFramework.dll assembly version between the deployed file on the remote server and your working local instance.

  3. Copy the deployment from the remote server into a local folder, point IIS at it and then hook VS up running your project using Attach to Process on w3wp.exe. Set a breakpoint somewhere in the code and check that it remains a "hot" hit-able breakpoint and not an inactive one stating something along the lines of "The breakpoint will not currently be hit. The source line does not match..." This would indicate that the deployed code does not reflect a current, complete rebuild of what you are running in VS.

If you are using an automated build:

  1. Check that dependency DLLs are not being checked in and that the build machine is actively resolving NuGet packages properly.

  2. Check your references for EF, both before you upgrade the EF version (Source control revert all changes, use what was last built and deployed) Under the project explorer under References, select EntityFramework and check the path listed. It should be pointing to: {Your solution folder}\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll If it is pointing to anything like a \bin\debug etc. folder, remove the reference and repair to point at the NuGet package.

  3. If NuGet packages folder is checked in, make sure this folder is complete and up to date in source control. When checking in nuget folders (as opposed to package version locking) I find this needs to be done from Explorer / TFS as normal VS checkins won't include them in pending changes. (unlike /bin folder changes if you accommodate them.) package folder updates can be skipped when initial checkins were made but then things like .ignore files are added/updated causing newer .dll files not to be updated.

  4. Check for any stale or mismatched project files (.csproj/.vbproj) in your local environment vs. what is in source control. Often these can get flagged at some point as "Excluded Files" resulting in the automated build using out of date references.

Have a check through these and see if that identifies anything.

2
2/5/2020 3:05:48 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow