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:-

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.

these nuget packages: enter image description here

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

Popular posts from this blog

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -

php - Autoloader issue not returning Class -