Search code examples
.netoracleentity-frameworkdevartdotconnect

Runtime error while creating database context using dotConnect and Entity Framework 6


We're using DevArt dotConnect to connect to an Oracle backend. Our previous dev machines have all used dotConnect 8.4.254.4, which is what's checked into Subversion. I've set up a new dev machine and installed the newest version, which is 8.5.616.0. I've updated every 8.4 reference I could find, even doing a "Find in Files" across everything checked in. However, something about this version breaks our code. Basically, right when I try to create a database context:

using (var _context = new DbContext())

I get this exception:

The 'Instance' member of the Entity Framework provider type 'Devart.Data.Oracle.Entity.OracleEntityProviderServices, Devart.Data.Oracle.Entity, Version=8.5.616.0, Culture=neutral, PublicKeyToken=09af7300eec23701' did not return an object that inherits from 'System.Data.Entity.Core.Common.DbProviderServices'. Entity Framework providers must inherit from this class and the 'Instance' member must return the singleton instance of the provider. This may be because the provider does not support Entity Framework 6 or later; see http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

I've spent quite a while searching Stack Overflow for similar errors, and there's many (across many database systems as well). There's various solutions such as updating different .config files and assembly references, but I've pretty much tried all that. There were also some suggestions about moving the DLL out of the GAC and referring to it directly in Program Files, which I've also tried. I'm now at a loss. How can I track down the cause of this issue? I'm happy to add any more code or information that would be helpful, just ask.

Update:

I've noticed in the Object Browser if I go to the actual Devart.Data.Oracle.Entity.OracleEntityProviderServices class, the base type is missing:

enter image description here

I'm wondering if this is related to the problem.


Solution

  • Please check your *.config. The revision number of provider in the entityFramework section should be 6 (8.5.616.6) but it has to be 0 (8.5.616.0) in DbProviderFactories ( http://blog.devart.com/entity-framework-6-support-for-oracle-mysql-postgresql-sqlite-and-salesforce.html#ProviderRegistration ):

    <?xml version="1.0" encoding="utf-8"?>
    <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>
      <entityFramework>
        <providers>
          <provider invariantName="Devart.Data.Oracle" type="Devart.Data.Oracle.Entity.OracleEntityProviderServices, Devart.Data.Oracle.Entity, Version=8.5.616.6, Culture=neutral, PublicKeyToken=09af7300eec23701" />
        </providers>
      </entityFramework>
      <system.data>
        <DbProviderFactories>
          <remove invariant="Devart.Data.Oracle" />
          <add name="dotConnect for Oracle" invariant="Devart.Data.Oracle" description="Devart dotConnect for Oracle" type="Devart.Data.Oracle.OracleProviderFactory, Devart.Data.Oracle, Version=8.5.616.0, Culture=neutral, PublicKeyToken=09af7300eec23701" />
        </DbProviderFactories>
      </system.data>
    </configuration>
    

    Also remove references to the Devart.* assemblies and readd them:

    C:\Program Files (x86)\Devart\dotConnect\Oracle\Devart.Data.dll

    C:\Program Files (x86)\Devart\dotConnect\Oracle\Devart.Data.Oracle.dll

    C:\Program Files (x86)\Devart\dotConnect\Oracle\Entity\EF6\Devart.Data.Oracle.Entity.dll (its revision number is 6)

    Does this work?

    If you upgrade to v9.0, be aware of the naming changes: http://forums.devart.com/viewtopic.php?f=1&t=33571 > Entity Framework Assembly Name Change.