Page 1 of 1

EF6 + PostgreSQL: MetadataException

Posted: Mon 21 Jan 2013 17:39
by Mike Ershov
Hi,

I'm trying to connect my sample database using dotConnect for PostgreSQL + Entity Framework 6 + .Net 4.5 + VS2012.
Database First option + Self-Tracking Entities are used.

The following MetadataException is thrown (container was created without any error; exception occurs while trying to get the data):
Schema specified is not valid. Errors:

DataModel.ssdl(2,2) : error 0152: The 'Instance' member of the Entity Framework provider type 'Devart.Data.PostgreSql.Entity.PgSqlEntityProviderServices, Devart.Data.PostgreSql.Entity, Version=6.4.164.0, Culture=neutral, PublicKeyToken=09af7300eec23701' did not return an object that inherits from 'System.Data.Entity.Core.Common.DbProviderServices'. Entity Framework providers must extend from this class and the 'Instance' member must return the Singleton instance of the provider.
App settings were taken from this link: EF6 support for Oracle, MySQL and other.

Here is my configuration file:

Code: Select all

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
  </configSections>

  <connectionStrings>
    <add name="MigrationEntitiesConnectionString" connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl;provider=Devart.Data.PostgreSql;provider connection string="user id=postgres;password=123456;host=localhost;database=migration;schema=public;"" providerName="System.Data.EntityClient"/>
  </connectionStrings>

  <system.data>
    <DbProviderFactories>
      <remove invariant="Devart.Data.PostgreSql"/>
      <add name="dotConnect for PostgreSQL" invariant="Devart.Data.PostgreSql" description="Devart dotConnect for PostgreSQL" type="Devart.Data.PostgreSql.PgSqlProviderFactory, Devart.Data.PostgreSql, Version=6.4.164.0, Culture=neutral, PublicKeyToken=09af7300eec23701"/>
    </DbProviderFactories>
  </system.data>

  <entityFramework>
    <providers>
      <provider invariantName="Devart.Data.PostgreSql" type="Devart.Data.PostgreSql.Entity.PgSqlEntityProviderServices, Devart.Data.PostgreSql.Entity, Version=6.4.164.0, Culture=neutral, PublicKeyToken=09af7300eec23701">
        <migrationSqlGenerator type="Devart.Data.PostgreSql.Entity.Migrations.PgSqlEntityMigrationSqlGenerator, Devart.Data.PostgreSql.Entity, Version=6.4.164.0, Culture=neutral, PublicKeyToken=09af7300eec23701"/>
      </provider>
    </providers>
  </entityFramework>
</configuration>
What should i do to get it work?

Thanks,
M. Ershov

Re: EF6 + PostgreSQL: MethadataException

Posted: Tue 22 Jan 2013 11:00
by Pinturiccio
You've got a wrong assembly version (revision number):

Code: Select all

  <entityFramework>
    <providers>
      <provider invariantName="Devart.Data.PostgreSql" type="Devart.Data.PostgreSql.Entity.PgSqlEntityProviderServices, Devart.Data.PostgreSql.Entity, Version=6.4.164.6, Culture=neutral, PublicKeyToken=09af7300eec23701">
        <migrationSqlGenerator type="Devart.Data.PostgreSql.Entity.Migrations.PgSqlEntityMigrationSqlGenerator, Devart.Data.PostgreSql.Entity, Version=6.4.164.6, Culture=neutral, PublicKeyToken=09af7300eec23701"/>
      </provider>
    </providers>
  </entityFramework>

Re: EF6 + PostgreSQL: MethadataException

Posted: Tue 22 Jan 2013 11:14
by Mike Ershov
Great, it works!
Thank you for your quick and accurate response!

Thanks,
M. Ershov

Re: EF6 + PostgreSQL: MethadataException

Posted: Wed 23 Jan 2013 15:53
by Mike Ershov
That configuration works well when i'm using MS .Net Framework but it doesn't if i'm using Mono 3.0.3 and MonoDevelop.

ObjectContext throws the following exception:

Code: Select all

System.InvalidOperationException: The provider for invariant name 'Devart.Data.PostgreSql' is specified multiple times in the application configuration. The invariant name must be unique for each configured provider.
  at System.Data.Entity.Internal.ConfigFile.ProviderCollection.BaseAdd (System.Configuration.ConfigurationElement element) [0x00000] in <filename unknown>:0

  at System.Configuration.ConfigurationElementCollection.OnDeserializeUnrecognizedElement (System.String elementName, System.Xml.XmlReader reader) [0x00048] in C:\cygwin\sources\mono\mcs\class\System.Configuration\System.Configuration\ConfigurationElementCollection.cs:523

  at System.Configuration.ConfigurationElement.DeserializeElement (System.Xml.XmlReader reader, Boolean serializeCollectionKey) [0x002cc] in C:\cygwin\sources\mono\mcs\class\System.Configuration\System.Configuration\ConfigurationElement.cs:370

  at System.Configuration.ConfigurationElement.DeserializeElement (System.Xml.XmlReader reader, Boolean serializeCollectionKey) [0x0038d] in C:\cygwin\sources\mono\mcs\class\System.Configuration\System.Configuration\ConfigurationElement.cs:388

  at System.Configuration.ConfigurationSection.DoDeserializeSection (System.Xml.XmlReader reader) [0x000d7] in C:\cygwin\sources\mono\mcs\class\System.Configuration\System.Configuration\ConfigurationSection.cs:186

  at System.Configuration.ConfigurationSection.DeserializeSection (System.Xml.XmlReader reader) [0x00000] in C:\cygwin\sources\mono\mcs\class\System.Configuration\System.Configuration\ConfigurationSection.cs:194

  at System.Configuration.Configuration.GetSectionInstance (System.Configuration.SectionInfo config, Boolean createDefaultInstance) [0x000db] in C:\cygwin\sources\mono\mcs\class\System.Configuration\System.Configuration\Configuration.cs:305

  at System.Configuration.ConfigurationSectionCollection.get_Item (System.String name) [0x00032] in C:\cygwin\sources\mono\mcs\class\System.Configuration\System.Configuration\ConfigurationSectionCollection.cs:68

  at System.Configuration.Configuration.GetSection (System.String path) [0x00024] in C:\cygwin\sources\mono\mcs\class\System.Configuration\System.Configuration\Configuration.cs:254

  at System.Web.Configuration.WebConfigurationManager.GetSection (System.String sectionName, System.String path, System.Web.HttpContext context) [0x001d4] in C:\cygwin\sources\mono\mcs\class\System.Web\System.Web.Configuration_2.0\WebConfigurationManager.cs:504

  at System.Web.Configuration.WebConfigurationManager.GetSection (System.String sectionName) [0x00006] in C:\cygwin\sources\mono\mcs\class\System.Web\System.Web.Configuration_2.0\WebConfigurationManager.cs:414

  at System.Web.Configuration.HttpConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection (System.String configKey) [0x00000] in C:\cygwin\sources\mono\mcs\class\System.Web\System.Web.Configuration_2.0\HttpConfigurationSystem.cs:41

  at System.Configuration.ConfigurationManager.GetSection (System.String sectionName) [0x00006] in C:\cygwin\sources\mono\mcs\class\System.Configuration\System.Configuration\ConfigurationManager.cs:162

  at System.Data.Entity.Internal.AppConfig..ctor () [0x00000] in <filename unknown>:0

  at System.Data.Entity.Internal.AppConfig..cctor () [0x00000] in <filename unknown>:0
There are no registered providers in my machnie.config file (i've commented them out while trying to solve the issue).

It's really strange but when i'm tried to use an empty string or completely remove "invariantName" property from EF provider registration, the expection message is
The provider for invariant name '' is specified multiple times in the application configuration

Code: Select all

  <entityFramework>
    <providers>      
      <provider type="Devart.Data.PostgreSql.Entity.PgSqlEntityProviderServices...........
Is it Mono defect? Has anybody used dotConnect for PostgreQSL in Mono environment?

Re: EF6 + PostgreSQL: MetadataException

Posted: Fri 25 Jan 2013 15:34
by Shalex
Mike Ershov wrote:That configuration works well when i'm using MS .Net Framework but it doesn't if i'm using Mono 3.0.3

Code: Select all

System.InvalidOperationException: The provider for invariant name 'Devart.Data.PostgreSql' is specified multiple times in the application configuration. The invariant name must be unique for each configured provider.
It looks like a bug in Mono.
Try the following workaround. Do not use the entityFramework section in your *.config (implement code-based registration instead) and specify just:

Code: Select all

<configuration>

  <connectionStrings>
    <add name="MigrationEntitiesConnectionString" connectionString="metadata=res://*/DataModel.csdl|res://*/DataModel.ssdl|res://*/DataModel.msl;provider=Devart.Data.PostgreSql;provider connection string="user id=postgres;password=123456;host=localhost;database=migration;schema=public;"" providerName="System.Data.EntityClient"/>
  </connectionStrings>

  <system.data>
    <DbProviderFactories>
      <remove invariant="Devart.Data.PostgreSql"/>
      <add name="dotConnect for PostgreSQL" invariant="Devart.Data.PostgreSql" description="Devart dotConnect for PostgreSQL" type="Devart.Data.PostgreSql.PgSqlProviderFactory, Devart.Data.PostgreSql, Version=6.4.164.0, Culture=neutral, PublicKeyToken=09af7300eec23701"/>
    </DbProviderFactories>
  </system.data>

</configuration>
We have implemented EFv6-compatible providers of a full value. If Mono fully supports Entity Framework, dotConnect for PostgreSQL should work correctly on Mono as well.

Re: EF6 + PostgreSQL: MetadataException

Posted: Mon 28 Jan 2013 13:21
by Mike Ershov
Hi,

As for code-based registration, I was unable to specify DbConfigurationType attribute to my DbContext inheritor: this type is seems like missing in Mono version of EF (hmm, as I understand Mono team uses Codeplex sources of EF instead of ported version).
In any case it's not a really appropriate solution for us because our code to be migrated uses ObjectContext approach.

Tech support adviced me to use CopyToOutput instead of EmbedInAssembly option of metadata processing. And it completely solved my troubles - the test application is working now!

Thanks,
M. Ershov