I am using SQL Anywhere 17 and entity framework 6. When I try to get some data from the database I get this exception.
An exception of type 'System.InvalidCastException' occurred in
EntityFramework.dll but was not handled in user code
Additional information: [A]Sap.Data.SQLAnywhere.SAConnection
cannot be cast to [B]Sap.Data.SQLAnywhere.SAConnection. Type A originates
from 'Sap.Data.SQLAnywhere.v4.5, Version=17.0.0.10624, Culture=neutral,
PublicKeyToken=f222fc4333e0d400' in the context 'Default' at
location 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Sap.Data.SQLAnywhere.v4.5
\v4.0_17.0.0.10624__f222fc4333e0d400\Sap.Data.SQLAnywhere.v4.5.dll'. Type B
originates from 'Sap.Data.SQLAnywhere.EF6, Version=17.0.0.10624,
Culture=neutral, PublicKeyToken=f222fc4333e0d400' in the context 'Default' at
location 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Sap.Data.SQLAnywhere.EF6
\v4.0_17.0.0.10624__f222fc4333e0d400\Sap.Data.SQLAnywhere.EF6.dll'.
Here is my code,
public class SybaseConfiguration : DbConfiguration
{
public SybaseConfiguration()
{
SetProviderServices("Sap.Data.SQLAnywhere", SAProviderServices.Instance);
}
}
[DbConfigurationType(typeof(SybaseConfiguration))]
public partial class SomeDatabaseContext : DbContext
{ ... }
// Calling code,
using (var context = new SomeDatabaseContext(connectionString)
context.GetSomeRandomTable.ToList() // I get exception here.
When I make context object, only Sap.Data.SQLAnywehre.EF6 is loaded. But when I call GetSomeRandomTable it loads Sap.Data.SQLAnywhere.v4.5 (which it should not),
Debugger says that both Sap.Data.SQLAnywhere.v4.5 and Sap.Data.SQLAnywhere.EF6 are loaded.
Note that there is nothing in the config file. I am code base configuration.