TargetInvocationException EntityFramework 5.0.0.0 not found when running Add-Migration Initial

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
la2texas
Posts: 10
Joined: Wed 18 Dec 2013 05:56

TargetInvocationException EntityFramework 5.0.0.0 not found when running Add-Migration Initial

Post by la2texas » Wed 18 Dec 2013 06:04

We are wanting to move off of FluentMigrator + ODAC + EDMX to devArt dotConnect for oracle code first. My initial spike worked great (5-10 entities, blob, clob, m2m, 1 to many tests, etc...). I could add-migration, update-database fine.

Now I have moved on to the actual project at hand (165 tables). I reverse engineered the EDMX to fluent mappings, entities, and context. I moved everything around appropriately, the project now builds fine - with my new mappings + context. Enable-Migrations ran fine, but when I run add-migration I always get this error:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileLoadException: Could not load file or assembly 'EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at HII.QIS.Data.Migrations.Configuration..ctor()
--- End of inner exception stack trace ---
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.CreateConfiguration(Type configurationType)
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindConfiguration()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.GetMigrator()
at System.Data.Entity.Migrations.Design.ToolingFacade.GetPendingMigrationsRunner.RunCore()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
Exception has been thrown by the target of an invocation.

I have checked all projects and they all reference EF 4.4.0.0 (we are on .NET 4). I am references dotConnect for EF 4. Not sure what else to try here?

Shalex
Site Admin
Posts: 8247
Joined: Thu 14 Aug 2008 12:44

Re: TargetInvocationException EntityFramework 5.0.0.0 not found when running Add-Migration Initial

Post by Shalex » Wed 18 Dec 2013 14:52

la2texas wrote:I am references dotConnect for EF 4
Please make sure (via Debug > Windows > Modules) that your application loads Devart.Data.Oracle.Entity.dll from the \Program Files\Devart\dotConnect\Oracle\Entity\EF4\ folder.

If this doesn't help, send us a test project to reproduce the error in our environment.

la2texas
Posts: 10
Joined: Wed 18 Dec 2013 05:56

Re: TargetInvocationException EntityFramework 5.0.0.0 not found when running Add-Migration Initial

Post by la2texas » Wed 18 Dec 2013 15:00

I see that while the project is running, it is loading from:

Devart.Data.Oracle.Entity.dll C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Devart.Data.Oracle.Entity\v4.0_8.1.55.0__09af7300eec23701\Devart.Data.Oracle.Entity.dll

la2texas
Posts: 10
Joined: Wed 18 Dec 2013 05:56

Re: TargetInvocationException EntityFramework 5.0.0.0 not found when running Add-Migration Initial

Post by la2texas » Wed 18 Dec 2013 15:27

Well, when I removed this line from the Configuration constructor, it at least let me add-migration:

this.SetSqlGenerator(OracleConnectionInfo.InvariantName, new OracleEntityMigrationSqlGenerator());


When I add it back to attempt to update-database it gives me the same error. Our company would really like to get this going and plan to purchase dotConnect if it will work.

la2texas
Posts: 10
Joined: Wed 18 Dec 2013 05:56

Re: TargetInvocationException EntityFramework 5.0.0.0 not found when running Add-Migration Initial

Post by la2texas » Wed 18 Dec 2013 19:01

Is there anything else you can recommmend I try? It is pulling DevArt from the GAC. When I remove that line it will add-migration fine, but obviously I cannot generate the needed SQL while using a DevArt provider without that line.

If I run migrate.exe from the projectfolder\packages\EntityFramework-5.0.0.0\tools folder it gives the same error. Yet when I modify the migrate.exe.config to to a redirect Package Manager console gives the same error (yet I can run migrate.exe fine). Is there some other migrate.exe that gets run maybe?

I only have a certain amount of time to prove to our client that this library is worth using - we are tired of fiddling with EDMX files. Any help would be much appreciated.

Shalex
Site Admin
Posts: 8247
Joined: Thu 14 Aug 2008 12:44

Re: TargetInvocationException EntityFramework 5.0.0.0 not found when running Add-Migration Initial

Post by Shalex » Thu 19 Dec 2013 14:43

Is .NET Framework v4.5 installed on your workstation? If yes, our provider places Devart.Data.Oracle.Entity.dll and Devart.Data.Oracle.Entity.Migrations.dll from the \Program Files\Devart\dotConnect\Oracle\Entity\EF5\ folder to GAC and uses it by default. To switch to EFv4.4 in this case, try the following:
  • remove Devart.Data.Oracle.Entity.dll and Devart.Data.Oracle.Entity.Migrations.dll from your GAC (C:\Windows\Microsoft.Net\assembly\GAC_MSIL\)
  • run VS
  • add references to the Devart.Data.Oracle.Entity.*.dll assemblies from the \Program Files\Devart\dotConnect\Oracle\Entity\EF4\ folder

Shalex
Site Admin
Posts: 8247
Joined: Thu 14 Aug 2008 12:44

Re: TargetInvocationException EntityFramework 5.0.0.0 not found when running Add-Migration Initial

Post by Shalex » Thu 19 Dec 2013 15:25

There is another way to fix the problem: just add the following entry in your app.config.

Code: Select all

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" />
        <bindingRedirect oldVersion="5.0.0.0" newVersion="4.4.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

la2texas
Posts: 10
Joined: Wed 18 Dec 2013 05:56

Re: TargetInvocationException EntityFramework 5.0.0.0 not found when running Add-Migration Initial

Post by la2texas » Thu 19 Dec 2013 15:58

Awesome - removing from the GAC fixed the issue - now Add-Migration will run successfully. However, update-database failed with the following error:

System.MissingMethodException: Method not found: 'Devart.Common.Entity.c2 Devart.Common.Entity.a7.c()'.
at Devart.Common.Entity.Migrations.c.a(IEnumerable`1 A_0, String A_1)
at Devart.Data.Oracle.Entity.Migrations.OracleEntityMigrationSqlGenerator.Generate(IEnumerable`1 migrationOperations, String providerManifestToken)
at System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, XDocument targetModel, IEnumerable`1 operations, Boolean downgrading, Boolean auto)
at System.Data.Entity.Migrations.DbMigrator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.ApplyMigration(DbMigration migration, DbMigration lastMigration)
at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorScriptingDecorator.ScriptUpdate(String sourceMigration, String targetMigration)
at System.Data.Entity.Migrations.Design.ToolingFacade.ScriptUpdateRunner.RunCore()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
Method not found: 'Devart.Common.Entity.c2 Devart.Common.Entity.a7.c()'.

la2texas
Posts: 10
Joined: Wed 18 Dec 2013 05:56

Re: TargetInvocationException EntityFramework 5.0.0.0 not found when running Add-Migration Initial

Post by la2texas » Thu 19 Dec 2013 17:47

Ah - I think I have found the reason for this. I was inheriting from DropCreateDatabaseAlways - once I changes to MigrateToLatestVersion it at least does not give me that error. It does, unfortunately hard-crash VS now (just shuts down). Considering the initial migration is 3k lines long, with 165 tables - not sure how we might get around this initial migration? What log file might I post that will help you guys determine the reason for the crash?

la2texas
Posts: 10
Joined: Wed 18 Dec 2013 05:56

Re: TargetInvocationException EntityFramework 5.0.0.0 not found when running Add-Migration Initial

Post by la2texas » Thu 19 Dec 2013 18:26

And I am back to square one. I think the problem was a static constructor in my context was setting an initialization strategy that referenced my initialization strategy, so a StackOverflow was occuring. Once I fixed this, I am back to method not found exception. Here is my setup:

Code: Select all

public class DatabaseInitializer : MigrateDatabaseToLatestVersion<Context, Configuration>
    {
        public DatabaseInitializer()
        {
            
        }
    }

public Configuration()
        {
            AutomaticMigrationsEnabled = false;
            
            SetSqlGenerator(OracleConnectionInfo.InvariantName, new OracleEntityMigrationSqlGenerator());
        }

static Context()
        {
            Database.SetInitializer<Context>(new DatabaseInitializer());
        }
Error:


PM> Update-Database -Script
Applying code-based migrations: [201312191551456_Initial].
Applying code-based migration: 201312191551456_Initial.
System.MissingMethodException: Method not found: 'Devart.Common.Entity.c2 Devart.Common.Entity.a7.c()'.
at Devart.Common.Entity.Migrations.c.a(IEnumerable`1 A_0, String A_1)
at Devart.Data.Oracle.Entity.Migrations.OracleEntityMigrationSqlGenerator.Generate(IEnumerable`1 migrationOperations, String providerManifestToken)
at System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, XDocument targetModel, IEnumerable`1 operations, Boolean downgrading, Boolean auto)
at System.Data.Entity.Migrations.DbMigrator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.ApplyMigration(DbMigration migration, DbMigration lastMigration)
at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorScriptingDecorator.ScriptUpdate(String sourceMigration, String targetMigration)
at System.Data.Entity.Migrations.Design.ToolingFacade.ScriptUpdateRunner.RunCore()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
Method not found: 'Devart.Common.Entity.c2 Devart.Common.Entity.a7.c()'.

la2texas
Posts: 10
Joined: Wed 18 Dec 2013 05:56

Re: TargetInvocationException EntityFramework 5.0.0.0 not found when running Add-Migration Initial

Post by la2texas » Thu 19 Dec 2013 19:52

I am trying different things, and updating my findings. Removing the GAC assembly causes my working project to fail with the same error(MethodMissingExceptioN). Once the GAC assembly is re-added, the working (smaller) project works as expected but I am back to the original error (EntityFramework 5.0.0.0 not found) on my real project. I have tried adding the bindingRedirect to my startup project, but everytime it is removed when I build.

So:

Why would devArt add assemblies into the GAC for .NET 4.5 if it is available and always use those if you have another version (.net 4 versioned assembly) that also needs to be referenced. How can I overcome this?

Shalex
Site Admin
Posts: 8247
Joined: Thu 14 Aug 2008 12:44

Re: TargetInvocationException EntityFramework 5.0.0.0 not found when running Add-Migration Initial

Post by Shalex » Fri 20 Dec 2013 10:29

la2texas wrote:System.MissingMethodException: Method not found: 'Devart.Common.Entity.c2 Devart.Common.Entity.a7.c()'.
at Devart.Common.Entity.Migrations.c.a(IEnumerable`1 A_0, String A_1)
at Devart.Data.Oracle.Entity.Migrations.OracleEntityMigrationSqlGenerator.Generate(IEnumerable`1 migrationOperations, String providerManifestToken)
This problem occurs when the versions of Devart.Data.Oracle.Entity.dll and Devart.Data.Oracle.Entity.Migrations.dll are messed up. For example: one assembly is from the \Program Files\Devart\dotConnect\Oracle\Entity\EF4\ folder, and another one is from \Program Files\Devart\dotConnect\Oracle\Entity\EF5\.
Shalex wrote:There is another way to fix the problem: just add the following entry in your app.config.

Code: Select all

    <configuration>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" />
            <bindingRedirect oldVersion="5.0.0.0" newVersion="4.4.0.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    </configuration>
Have you tried this approach (instead of removing the Devart.* assemblies from GAC)? If this doesn't help, let us know.

la2texas
Posts: 10
Joined: Wed 18 Dec 2013 05:56

Re: TargetInvocationException EntityFramework 5.0.0.0 not found when running Add-Migration Initial

Post by la2texas » Fri 20 Dec 2013 14:01

No this still does not work.

Shalex
Site Admin
Posts: 8247
Joined: Thu 14 Aug 2008 12:44

Re: TargetInvocationException EntityFramework 5.0.0.0 not found when running Add-Migration Initial

Post by Shalex » Tue 24 Dec 2013 12:48

We have answered you by e-mail.

Post Reply