c# - The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception -
i have asp.net mvc site.
technology stack
- asp.net 4.6
- c#.net
- ef 6
- mysql -database
while trying generate database using nuget command:-
enable-migrations -force i getting below exception
the type initializer 'system.data.entity.migrations.dbmigrationsconfiguration`1' threw exception.
following things cross checked & tried me:-
the type initializer 'system.data.entity.internal.appconfig' threw exception on sub website
the type initializer 'system.data.entity.internal.appconfig' threw exception
my app.config:-
<connectionstrings> <add name="mydbcontext" providername="mysql.data.mysqlclient" connectionstring="server=localhost;port=8080;database=mydb;uid=root;password=" /> </connectionstrings> <entityframework> <defaultconnectionfactory type="mysql.data.entity.mysqlconnectionfactory, mysql.data.entity.ef6" /> <providers> <provider invariantname="mysql.data.mysqlclient" type="mysql.data.mysqlclient.mysqlproviderservices, mysql.data.entity.ef6, version=6.8.8.0, culture=neutral, publickeytoken=c5687fc88969c44d"></provider> </providers>
this configuration worked me:
<?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> <startup> <supportedruntime version="v4.0" sku=".netframework,version=v4.5.2" /> </startup> <entityframework> <defaultconnectionfactory type="system.data.entity.infrastructure.sqlconnectionfactory, entityframework" /> <providers> <provider invariantname="system.data.sqlclient" type="system.data.entity.sqlserver.sqlproviderservices, entityframework.sqlserver" /> <provider invariantname="mysql.data.mysqlclient" type="mysql.data.mysqlclient.mysqlproviderservices, mysql.data.entity.ef6, version=6.8.3.0, culture=neutral, publickeytoken=c5687fc88969c44d"></provider> </providers> </entityframework> <system.data> <dbproviderfactories> <remove invariant="mysql.data.mysqlclient" /> <add name="mysql data provider" invariant="mysql.data.mysqlclient" description=".net framework data provider mysql" type="mysql.data.mysqlclient.mysqlclientfactory, mysql.data, version=6.8.3.0, culture=neutral, publickeytoken=c5687fc88969c44d" /> </dbproviderfactories> </system.data> <connectionstrings> <add name="mylocaldatabase" providername="mysql.data.mysqlclient" connectionstring="server=localhost;port=3306;database=mycontext;uid=root;password=********" /> </connectionstrings> </configuration> i getting errors similar yours because of wrong installation of mysql connector client in development machine. installed mysql connector nuget packages within visual studio, not enough. needed install mysql client downloaded mysql website. after type errors went away.
and the download page of mysql connector downloaded , installed manually.
note: defaultconnectionfactory value never used if specify explicitly type of provider. in case doesn't matter value have in configuration file in setting. see point 3 in this reference doc page in mysql website.
i recommend check if mysql correctly installed in machine using mysql command line client console. try connect server outside visual studio connection string values.

Comments
Post a Comment