Quantcast
Channel: Entity Framework
Viewing all articles
Browse latest Browse all 10318

Commented Issue: The Ssdl we save in __MigrationHistory table is invalid [1037]

$
0
0
The Ssdl we save in the __MigrationHistory table is invalid. For some reason the error is not reported on the .NET Framework 4 when reading StoreItemCollection (either a weird xsd bug or we setup something incorrectly since the error is reported when opening the ssdl (as xml) in VS). However on Mono Key element is marked as invalid. This results in an assert following by NRE on Mono. The bug is that we write IsSystem attribute on the Key element (```<Key p5:IsSystem=""true"">```) while according to the schema the Key element cannot have any attributes - even in a non-empty, non-EF namespace.

__Note this seems to completely block EF6 on Mono__

Repro - this does not throw on .NET Framework
```
var ssdl = XDocument.Parse(
@"<Schema Namespace=""CodeFirstDatabaseSchema"" Provider=""Devart.Data.MySql"" ProviderManifestToken=""MySQL"" Alias=""Self"" xmlns=""http://schemas.microsoft.com/ado/2009/11/edm/ssdl"">
<EntityContainer Name=""CodeFirstDatabase"">
<EntitySet Name=""HistoryRow"" EntityType=""Self.HistoryRow"" Schema=""dbo"" Table=""__MigrationHistory"" p6:IsSystem=""true"" xmlns:p6=""http://schemas.microsoft.com/ado/2012/10/edm/migrations"" />
</EntityContainer>
<EntityType Name=""HistoryRow"" p5:IsSystem=""true"" xmlns:p5=""http://schemas.microsoft.com/ado/2012/10/edm/migrations"">
<Key p5:IsSystem=""true"">
<PropertyRef Name=""MigrationId"" p5:IsSystem=""true"" />
<PropertyRef Name=""ContextKey"" p5:IsSystem=""true"" />
</Key>
<Property Name=""MigrationId"" Type=""varchar"" MaxLength=""255"" Nullable=""false"" p5:IsSystem=""true"" />
<Property Name=""ContextKey"" Type=""varchar"" MaxLength=""512"" Nullable=""false"" p5:IsSystem=""true"" />
<Property Name=""Model"" Type=""longblob"" Nullable=""false"" p5:IsSystem=""true"" />
<Property Name=""ProductVersion"" Type=""varchar"" MaxLength=""32"" Nullable=""false"" p5:IsSystem=""true"" />
</EntityType>
</Schema>");

new StoreItemCollection(new[] { ssdl.CreateReader() });
```
but on Mono this throws NRE:

```
Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
at System.Data.Entity.Core.EntityModel.SchemaObjectModel.EntityKeyElement.Validate () [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.EntityModel.SchemaObjectModel.SchemaEntityType.Validate () [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.EntityModel.SchemaObjectModel.Schema.Validate () [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.EntityModel.SchemaObjectModel.Schema.ValidateSchema () [0x00000] in <filename unknown>:0
at System.Data.Entity.Core.EntityModel.SchemaObjectModel.SchemaManager.ParseAndValidate (IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, SchemaDataModelOption dataModel, System.Data.Entity.Core.EntityModel.SchemaObjectModel.AttributeValueNotification providerNotification, System.Data.Entity.Core.EntityModel.SchemaObjectModel.AttributeValueNotification providerManifestTokenNotification, System.Data.Entity.Core.EntityModel.SchemaObjectModel.ProviderManifestNeeded providerManifestNeeded, IList`1& schemaCollection) [0x00000] in <filename unknown>:0
...
```

The fix is to allow xs:AnyAttribet on the TEntityKeyElement
```
<xs:complexType name="TEntityKeyElement">
<xs:sequence>
<xs:element name="PropertyRef" type="edm:TPropertyRef" minOccurs="1" maxOccurs="unbounded" />
<xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
<!-- add this -->
<xs:anyAttribute namespace="##other" processContents="lax" />
</xs:complexType>
```

Related issue: https://entityframework.codeplex.com/workitem/1038
Comments: I'm seeing the same problem. In fact, I'm stuck... I cannot migrate my model any longer. I'm now on "6.0.0-beta1-20517" and using SqlCe. I hope you can fix this soon... Please... Here is a dump from the package manager console: PM> add-migration Evo10 -Force System.Data.Entity.Core.MappingException: Schema specified is not valid. Errors: <File Unknown>(0,0) : error 2025: XML Schema validation failed for mapping schema. Schema Error Information : The 'http://schemas.microsoft.com/ado/2012/10/edm/migrations:IsSystem' attribute is not declared.. <File Unknown>(0,0) : error 2025: XML Schema validation failed for mapping schema. Schema Error Information : The 'http://schemas.microsoft.com/ado/2012/10/edm/migrations:IsSystem' attribute is not declared.. <File Unknown>(0,0) : error 2025: XML Schema validation failed for mapping schema. Schema Error Information : The 'http://schemas.microsoft.com/ado/2012/10/edm/migrations:IsSystem' attribute is not declared.. <File Unknown>(0,0) : error 2025: XML Schema validation failed for mapping schema. Schema Error Information : The 'http://schemas.microsoft.com/ado/2012/10/edm/migrations:IsSystem' attribute is not declared.. <File Unknown>(0,0) : error 2025: XML Schema validation failed for mapping schema. Schema Error Information : The 'http://schemas.microsoft.com/ado/2012/10/edm/migrations:IsSystem' attribute is not declared.. <File Unknown>(0,0) : error 2025: XML Schema validation failed for mapping schema. Schema Error Information : The 'http://schemas.microsoft.com/ado/2012/10/edm/migrations:IsSystem' attribute is not declared.. <File Unknown>(0,0) : error 2025: XML Schema validation failed for mapping schema. Schema Error Information : The 'http://schemas.microsoft.com/ado/2012/10/edm/migrations:IsSystem' attribute is not declared.. at System.Data.Entity.Core.Mapping.StorageMappingItemCollection.Init(EdmItemCollection edmCollection, StoreItemCollection storeCollection, IEnumerable`1 xmlReaders, IList`1 filePaths, Boolean throwOnError) at System.Data.Entity.Core.Mapping.StorageMappingItemCollection..ctor(EdmItemCollection edmCollection, StoreItemCollection storeCollection, IEnumerable`1 xmlReaders) at System.Data.Entity.Utilities.XDocumentExtensions.GetStorageMappingItemCollection(XDocument model, DbProviderInfo& providerInfo) at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.Diff(XDocument sourceModel, XDocument targetModel, ModificationCommandTreeGenerator modificationCommandTreeGenerator, MigrationSqlGenerator migrationSqlGenerator) at System.Data.Entity.Migrations.DbMigrator.Scaffold(String migrationName, String namespace, Boolean ignoreChanges) at System.Data.Entity.Migrations.Design.MigrationScaffolder.Scaffold(String migrationName, Boolean ignoreChanges) at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Scaffold(MigrationScaffolder scaffolder) at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Run() at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner) at System.Data.Entity.Migrations.Design.ToolingFacade.Scaffold(String migrationName, String language, String rootNamespace, Boolean ignoreChanges) at System.Data.Entity.Migrations.AddMigrationCommand.Execute(String name, Boolean force, Boolean ignoreChanges) at System.Data.Entity.Migrations.AddMigrationCommand.<>c__DisplayClass2.<.ctor>b__0() at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command) Schema specified is not valid. Errors: <File Unknown>(0,0) : error 2025: XML Schema validation failed for mapping schema. Schema Error Information : The 'http://schemas.microsoft.com/ado/2012/10/edm/migrations:IsSystem' attribute is not declared.. <File Unknown>(0,0) : error 2025: XML Schema validation failed for mapping schema. Schema Error Information : The 'http://schemas.microsoft.com/ado/2012/10/edm/migrations:IsSystem' attribute is not declared.. <File Unknown>(0,0) : error 2025: XML Schema validation failed for mapping schema. Schema Error Information : The 'http://schemas.microsoft.com/ado/2012/10/edm/migrations:IsSystem' attribute is not declared.. <File Unknown>(0,0) : error 2025: XML Schema validation failed for mapping schema. Schema Error Information : The 'http://schemas.microsoft.com/ado/2012/10/edm/migrations:IsSystem' attribute is not declared.. <File Unknown>(0,0) : error 2025: XML Schema validation failed for mapping schema. Schema Error Information : The 'http://schemas.microsoft.com/ado/2012/10/edm/migrations:IsSystem' attribute is not declared.. <File Unknown>(0,0) : error 2025: XML Schema validation failed for mapping schema. Schema Error Information : The 'http://schemas.microsoft.com/ado/2012/10/edm/migrations:IsSystem' attribute is not declared.. <File Unknown>(0,0) : error 2025: XML Schema validation failed for mapping schema. Schema Error Information : The 'http://schemas.microsoft.com/ado/2012/10/edm/migrations:IsSystem' attribute is not declared.. PM>

Viewing all articles
Browse latest Browse all 10318

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>