Entity Framework Seed method exception
Asked Answered
S

1

4

I am using Entity Framework 6 with an MVC5 webapi2 project against an Oracle database.

I am trying to add some ApplicationRoles in the Seed method, but when I execute update-database I get this exception:

Running Seed method. System.Runtime.Serialization.SerializationException: Type is not resolved for member 'Oracle.ManagedDataAccess.Client.OracleException,Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342'. at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate) at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner) at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force) at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0() at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command) Type is not resolved for member 'Oracle.ManagedDataAccess.Client.OracleException,Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342'.

My code in the Seed method:

var roleStore = new RoleStore<IdentityRole>(context);
var roleManager = new RoleManager<IdentityRole>(roleStore);

if (!context.Roles.Any(r => r.Name == "USER"))
{
    var role = new IdentityRole("USER");
    roleManager.Create(role);
}

update-database is creating my tables without any problem, it's just the Seed method which has a problem.

Does anyone have any suggestions as to what the problem could be please?

Thanks.

Sphery answered 14/8, 2015 at 9:35 Comment(0)
I
6

Installing Oracle.ManagedDataAccess.dll to GAC resolved my issue. If you installed Oracle Client or Oracle Database on your machine that might be the cause.

C:\Windows\system32>cd E:\smn\packages\Oracle.ManagedDataAccess.12.1.021\lib\net40

C:\Windows\system32>e:

E:\smn\packages\Oracle.ManagedDataAccess.12.1.021\lib\net40>"C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\gacutil.exe" /i Oracle.ManagedDataAccess.dll
Microsoft (R) .NET Global Assembly Cache Utility.  Version 4.0.30319.33440
Copyright (c) Microsoft Corporation.  All rights reserved.

Assembly successfully added to the cache
Isabelleisac answered 3/10, 2015 at 15:37 Comment(1)
Note, you don't need to use the gacutil path shown above (especially those that don't have the sdk shown). If you have VS installed, simply use the developer prompt. gacutil is on path.Pawsner

© 2022 - 2024 — McMap. All rights reserved.