1

Closed

Assert thrown when running P1 test case "ChangeComplexReturnTypeToCompatible"

description

The test case has following assert twice. After clicking Ignore on it, the test case passes eventually. Here is the text from the Assert.
---------------------------
Assertion Failed: Abort=Quit, Retry=Debug, Ignore=Continue
---------------------------
propertyMappings order does not correspond to the order of properties in the structuredType.



   at System.Data.Entity.Core.Mapping.StorageMappingItemLoader.TryConvertToProperyMappings(StructuralType structuralType, RowType cTypeTvfElementType, RowType sTypeTvfElementType, EdmFunction functionImport, FunctionImportStructuralTypeMappingKB functionImportKB, IXmlLineInfo navLineInfo, List`1& propertyMappings)

   at System.Data.Entity.Core.Mapping.StorageMappingItemLoader.TryCreateFunctionImportMappingComposableWithStructuralResult(EdmFunction functionImport, EdmFunction cTypeTargetFunction, List`1 typeMappings, RowType cTypeTvfElementType, RowType sTypeTvfElementType, IXmlLineInfo lineInfo, FunctionImportMappingComposable& mapping)

   at System.Data.Entity.Core.Mapping.StorageMappingItemLoader.LoadFunctionImportMapping(XPathNavigator nav, StorageEntityContainerMapping entityContainerMapping)

   at System.Data.Entity.Core.Mapping.StorageMappingItemLoader.LoadEntityContainerMappingChildNodes(XPathNavigator......

<truncated>
---------------------------
Abort   Retry   Ignore   
---------------------------
This is complete stack trace
>   EntityFramework.dll!System.Data.Entity.Core.Mapping.StorageMappingItemLoader.TryConvertToProperyMappings(System.Data.Entity.Core.Metadata.Edm.StructuralType structuralType, System.Data.Entity.Core.Metadata.Edm.RowType cTypeTvfElementType, System.Data.Entity.Core.Metadata.Edm.RowType sTypeTvfElementType, System.Data.Entity.Core.Metadata.Edm.EdmFunction functionImport, System.Data.Entity.Core.Mapping.FunctionImportStructuralTypeMappingKB functionImportKB, System.Xml.IXmlLineInfo navLineInfo, out System.Collections.Generic.List<System.Data.Entity.Core.Mapping.StoragePropertyMapping> propertyMappings) Line 2695 + 0x191 bytes    C#
    EntityFramework.dll!System.Data.Entity.Core.Mapping.StorageMappingItemLoader.TryCreateFunctionImportMappingComposableWithStructuralResult(System.Data.Entity.Core.Metadata.Edm.EdmFunction functionImport, System.Data.Entity.Core.Metadata.Edm.EdmFunction cTypeTargetFunction, System.Collections.Generic.List<System.Data.Entity.Core.Mapping.FunctionImportStructuralTypeMapping> typeMappings, System.Data.Entity.Core.Metadata.Edm.RowType cTypeTvfElementType, System.Data.Entity.Core.Metadata.Edm.RowType sTypeTvfElementType, System.Xml.IXmlLineInfo lineInfo, out System.Data.Entity.Core.Mapping.FunctionImportMappingComposable mapping) Line 2316 + 0x1f bytes   C#
    EntityFramework.dll!System.Data.Entity.Core.Mapping.StorageMappingItemLoader.LoadFunctionImportMapping(System.Xml.XPath.XPathNavigator nav, System.Data.Entity.Core.Mapping.StorageEntityContainerMapping entityContainerMapping) Line 1712 + 0x2e bytes    C#
    EntityFramework.dll!System.Data.Entity.Core.Mapping.StorageMappingItemLoader.LoadEntityContainerMappingChildNodes(System.Xml.XPath.XPathNavigator nav, System.Data.Entity.Core.Mapping.StorageEntityContainerMapping entityContainerMapping, System.Data.Entity.Core.Metadata.Edm.EntityContainer storageEntityContainerType) Line 435 + 0x2e bytes C#
    EntityFramework.dll!System.Data.Entity.Core.Mapping.StorageMappingItemLoader.LoadEntityContainerMapping(System.Xml.XPath.XPathNavigator nav) Line 399 + 0x31 bytes  C#
    EntityFramework.dll!System.Data.Entity.Core.Mapping.StorageMappingItemLoader.LoadMappingChildNodes(System.Xml.XPath.XPathNavigator nav) Line 309 + 0x2d bytes   C#
    EntityFramework.dll!System.Data.Entity.Core.Mapping.StorageMappingItemLoader.LoadMappingItems(System.Xml.XPath.XPathNavigator nav) Line 243 + 0x1f bytes    C#
    EntityFramework.dll!System.Data.Entity.Core.Mapping.StorageMappingItemLoader.LoadMappingItems(System.Xml.XmlReader innerReader) Line 209 + 0x1f bytes   C#
    EntityFramework.dll!System.Data.Entity.Core.Mapping.StorageMappingItemLoader.StorageMappingItemLoader(System.Xml.XmlReader reader, System.Data.Entity.Core.Mapping.StorageMappingItemCollection storageMappingItemCollection, string fileName, System.Collections.Generic.Dictionary<System.Data.Entity.Core.Metadata.Edm.EdmMember,System.Collections.Generic.KeyValuePair<System.Data.Entity.Core.Metadata.Edm.TypeUsage,System.Data.Entity.Core.Metadata.Edm.TypeUsage>> scalarMemberMappings) Line 117 + 0x12 bytes C#
    EntityFramework.dll!System.Data.Entity.Core.Mapping.StorageMappingItemCollection.LoadItems(System.Collections.Generic.IEnumerable<System.Xml.XmlReader> xmlReaders, System.Collections.Generic.IList<string> mappingSchemaUris, System.Collections.Generic.Dictionary<System.Data.Entity.Core.Metadata.Edm.EntitySetBase,System.Data.Entity.Core.Mapping.ViewGeneration.GeneratedView> userDefinedQueryViewsDict, System.Collections.Generic.Dictionary<System.Data.Entity.Core.Common.Utils.Pair<System.Data.Entity.Core.Metadata.Edm.EntitySetBase,System.Data.Entity.Core.Common.Utils.Pair<System.Data.Entity.Core.Metadata.Edm.EntityTypeBase,bool>>,System.Data.Entity.Core.Mapping.ViewGeneration.GeneratedView> userDefinedQueryViewsOfTypeDict, double expectedVersion) Line 1307 + 0x2b bytes C#
    EntityFramework.dll!System.Data.Entity.Core.Mapping.StorageMappingItemCollection.Init(System.Data.Entity.Core.Metadata.Edm.EdmItemCollection edmCollection, System.Data.Entity.Core.Metadata.Edm.StoreItemCollection storeCollection, System.Collections.Generic.IEnumerable<System.Xml.XmlReader> xmlReaders, System.Collections.Generic.IList<string> filePaths, bool throwOnError) Line 740 + 0x27 bytes C#
    EntityFramework.dll!System.Data.Entity.Core.Mapping.StorageMappingItemCollection.StorageMappingItemCollection(System.Data.Entity.Core.Metadata.Edm.EdmItemCollection edmItemCollection, System.Data.Entity.Core.Metadata.Edm.StoreItemCollection storeItemCollection, System.Collections.Generic.IEnumerable<System.Xml.XmlReader> xmlReaders, System.Collections.Generic.IList<string> filePaths, out System.Collections.Generic.IList<System.Data.Entity.Core.Metadata.Edm.EdmSchemaError> errors) Line 673 + 0x1d bytes  C#
    EntityFramework.dll!System.Data.Entity.Core.Mapping.StorageMappingItemCollection.Create(System.Data.Entity.Core.Metadata.Edm.EdmItemCollection edmItemCollection, System.Data.Entity.Core.Metadata.Edm.StoreItemCollection storeItemCollection, System.Collections.Generic.IEnumerable<System.Xml.XmlReader> xmlReaders, System.Collections.Generic.IList<string> filePaths, out System.Collections.Generic.IList<System.Data.Entity.Core.Metadata.Edm.EdmSchemaError> errors) Line 1500 + 0x25 bytes   C#
    Microsoft.Data.Entity.Design.Model.dll!Microsoft.Data.Entity.Design.Model.Validation.RuntimeMetadataValidator.ValidateMapping(Microsoft.Data.Entity.Design.Model.EntityDesignArtifact designArtifact, System.Data.Entity.Core.Metadata.Edm.EdmItemCollection edmItemCollection, System.Data.Entity.Core.Metadata.Edm.StoreItemCollection storeItemCollection) + 0x2bf bytes 
    Microsoft.Data.Entity.Design.Model.dll!Microsoft.Data.Entity.Design.Model.Validation.RuntimeMetadataValidator.ValidateArtifactSet(Microsoft.Data.Entity.Design.Model.EFArtifactSet artifactSet, bool forceValidation, bool validateMsl, bool runViewGen) + 0x16e bytes  
    Microsoft.Data.Entity.Design.Model.dll!Microsoft.Data.Entity.Design.Model.Validation.RuntimeMetadataValidator.ValidateAndCompileMappings(Microsoft.Data.Entity.Design.Model.EFArtifactSet artifactSet, bool validateMapping) + 0x35 bytes   
    Microsoft.Data.Entity.Design.Model.dll!Microsoft.Data.Entity.Design.Model.EntityDesignModelManager.ValidateAndCompileMappings(Microsoft.Data.Entity.Design.Model.EntityDesignArtifactSet artifactSet, bool doEscherValidation) + 0x143 bytes    
    Microsoft.Data.Entity.Design.dll!Microsoft.Data.Entity.Design.VisualStudio.VisualStudioEdmxValidator.ValidateArtifactAndWriteErrors(Microsoft.Data.Entity.Design.Model.EFArtifact artifact, Microsoft.VisualStudio.Shell.Interop.IVsHierarchy hierarchy, uint itemId, bool doEscherValidation) + 0x219 bytes    
    Microsoft.Data.Entity.Design.dll!Microsoft.Data.Entity.Design.VisualStudio.VisualStudioEdmxValidator.ValidateArtifactAndWriteErrors(Microsoft.Data.Entity.Design.Model.EFArtifact artifact, Microsoft.Data.Entity.Design.VisualStudio.VSFileFinder.VSFileInfo vsFileInfo, bool doEscherValidation) + 0x41 bytes 
    Microsoft.Data.Entity.Design.dll!Microsoft.Data.Entity.Design.VisualStudio.VisualStudioEdmxValidator.LoadAndValidateFiles(System.Collections.Generic.IEnumerable<Microsoft.Data.Entity.Design.VisualStudio.VSFileFinder.VSFileInfo> edmxFilesToValidate, bool doEscherValidation, System.Func<Microsoft.Data.Entity.Design.Model.EFArtifact,bool> shouldValidateArtifact) + 0x17c bytes 
    Microsoft.Data.Entity.Design.dll!Microsoft.Data.Entity.Design.VisualStudio.VisualStudioEdmxValidator.LoadAndValidateAllFilesInProject(Microsoft.VisualStudio.Shell.Interop.IVsHierarchy pHierProj, bool doEscherValidation, System.Func<Microsoft.Data.Entity.Design.Model.EFArtifact,bool> shouldValidateArtifact) + 0xc8 bytes    
    Microsoft.Data.Entity.Design.dll!Microsoft.Data.Entity.Design.VisualStudio.EdmUpdateSolutionEvents.Microsoft.VisualStudio.Shell.Interop.IVsUpdateSolutionEvents2.UpdateProjectCfg_Begin(Microsoft.VisualStudio.Shell.Interop.IVsHierarchy pHierProj, Microsoft.VisualStudio.Shell.Interop.IVsCfg pCfgProj, Microsoft.VisualStudio.Shell.Interop.IVsCfg pCfgSln, uint dwAction, ref int pfCancel) + 0xa4 bytes   
"
The file where the assert is: \entityframework\src\EntityFramework\Core\Mapping\StorageMappingItemLoader.cs
Closed Jul 27, 2013 at 12:48 AM by Mugdhak
Verified that the assert is not thrown anymore and the test now fails, so it is no more returning false positive.

comments

RoMiller wrote Jul 11, 2013 at 11:09 PM

EF Team Triage: If the state is ok after clicking Ignore we can punt to after EF6.

lajones wrote Jul 15, 2013 at 11:37 PM

Issue is that at line 2677 of StorageMappingItemLoader (and also at line 2667 though we're not hitting that in this scenario) we are creating and adding errors to the list but failing to set the local flag errorsFound to true.

Later this means we a) raise the Assert and b) return true where we should return false. If we had returned false we would have returned false immediately from the next method in the call stack (and so on down the stack); instead we create other objects and return an invalid true - which leads the runtime to think it's constructing a valid model when it isn't.

Recommend we fix. Fix is fairly simple - just setting errorsFound = true in those 2 locations.

lajones wrote Jul 16, 2013 at 5:53 PM

For testing here's a simpler repro for outside of the QA tests.
  • Have a DB with 2 TVFs which return tables of different "shapes".
  • Create a new project and add an EDMX which points to that DB. Include the 2 TVFs (note: you should get 2 complex types created representing the return types of the 2 TVFs)
  • Open the EDMX and from there open the Model Browser (if not already open)
  • In the Model Browser expand Function Imports and select one of the TVFs, right-click it and select "Function Import Mapping"
  • In the Mapping Details window on the line that says "Maps to <Function_Name>", select that line and in the drop down select the other incompatible Function.
  • Right-click on the background of the designer and select "Validate"
This used to bring up an Assertion-Failed dialog with the above stack trace. Fix will be not to see this dialog - just the errors in the Error List window (which you should expect because the mapping will no longer work).

lajones wrote Jul 16, 2013 at 5:57 PM

First fix was to prevent the EF6 provider not being registered if you open and close the above project - #d29f610. This was preventing us seeing the above dialog if you had ever closed the project once you created it.

lajones wrote Jul 16, 2013 at 6:57 PM

Second fix checked into runtime - we were failing to assign the errorFound flag when we found that sort of error. This in turn triggered the Assert (and made the method incorrectly return true when it should return false which had knock-on effects).

Checked in with #7e69c1c.

lajones wrote Jul 16, 2013 at 9:30 PM

Checked updated entity framework submodule into designer - #57ad265.