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: @janoveh: I believe you are actually seeing this: http://entityframework.codeplex.com/workitem/1128. It's a bit different issue even though on the surface looks the same.
__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: @janoveh: I believe you are actually seeing this: http://entityframework.codeplex.com/workitem/1128. It's a bit different issue even though on the surface looks the same.