There was a problem with running an application written in C # (WPF) with connection to the MySql database using ADO.NET Entities. The error is as follows:
System.TypeInitializationException Π½Π΅ ΠΎΠ±ΡΠ°Π±ΠΎΡΠ°Π½ΠΎ ΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»ΡΡΠΊΠΈΠΌ ΠΊΠΎΠ΄ΠΎΠΌ HResult=-2146233036 Message=ΠΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·Π°ΡΠΎΡ ΡΠΈΠΏΠ° "System.Data.Entity.Internal.AppConfig" Π²ΡΠ΄Π°Π» ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅. Source=EntityFramework TypeName=System.Data.Entity.Internal.AppConfig StackTrace: Π² System.Data.Entity.Internal.AppConfig.get_DefaultInstance() Π² System.Data.Entity.Internal.LazyInternalConnection..ctor(DbContext context, String nameOrConnectionString) Π² System.Data.Entity.DbContext..ctor(String nameOrConnectionString) Π² AccessToClientsDB.clientdbEntities..ctor() Π² c:\Users\Andrey\Desktop\...\ClientService\Client\AccessToClientsDB\clientdb.Context.cs:ΡΡΡΠΎΠΊΠ° 18 Π² AccessToClientsDB.AccessToClientsDB..ctor() Π² c:\Users\Andrey\Desktop\...\ClientService\Client\AccessToClientsDB\AccessToClientsDB.cs:ΡΡΡΠΎΠΊΠ° 13 Π² GUI.MainWindow..ctor() Π² c:\Users\Andrey\Desktop\...\ClientService\Client\GUI\MainWindow.xaml.cs:ΡΡΡΠΎΠΊΠ° 26 InnerException: System.Configuration.ConfigurationErrorsException HResult=-2146232062 Message=Π‘ΠΈΡΡΠ΅ΠΌΠ° ΠΊΠΎΠ½ΡΠΈΠ³ΡΡΠ°ΡΠΈΠΈ Π½Π΅ ΠΏΡΠΎΡΠ»Π° ΠΈΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·Π°ΡΠΈΡ Source=System.Configuration BareMessage=Π‘ΠΈΡΡΠ΅ΠΌΠ° ΠΊΠΎΠ½ΡΠΈΠ³ΡΡΠ°ΡΠΈΠΈ Π½Π΅ ΠΏΡΠΎΡΠ»Π° ΠΈΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·Π°ΡΠΈΡ Line=0 StackTrace: Π² System.Configuration.ClientConfigurationSystem.OnConfigRemoved(Object sender, InternalConfigEventArgs e) Π² System.Configuration.Internal.InternalConfigRoot.OnConfigRemoved(InternalConfigEventArgs e) Π² System.Configuration.Internal.InternalConfigRoot.RemoveConfigImpl(String configPath, BaseConfigurationRecord configRecord) Π² System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) Π² System.Configuration.BaseConfigurationRecord.GetSection(String configKey) Π² System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName) Π² System.Configuration.ConfigurationManager.GetSection(String sectionName) Π² System.Data.Entity.Internal.AppConfig..ctor() Π² System.Data.Entity.Internal.AppConfig..cctor() InnerException: System.Configuration.ConfigurationErrorsException HResult=-2146232062 Message= ΠΠ΅ΠΈΠ·Π²Π΅ΡΡΠ½ΡΠΉ ΡΠ°Π·Π΄Π΅Π» ΠΊΠΎΠ½ΡΠΈΠ³ΡΡΠ°ΡΠΈΠΈ userSettings. (C:\Users\Andrey\AppData\Local\GUI\GUI.vshost.exe_Url_ev1ciwvrswduwtnpzk5phoigckrk3o4m\1.0.0.0\user.config line 3) Source=System.Configuration BareMessage= ΠΠ΅ΠΈΠ·Π²Π΅ΡΡΠ½ΡΠΉ ΡΠ°Π·Π΄Π΅Π» ΠΊΠΎΠ½ΡΠΈΠ³ΡΡΠ°ΡΠΈΠΈ userSettings. Filename=C:\Users\Andrey\AppData\Local\GUI\GUI.vshost.exe_Url_ev1ciwvrswduwtnpzk5phoigckrk3o4m\1.0.0.0\user.config Line=3 StackTrace: Π² System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal) Π² System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors) Π² System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors() Π² System.Configuration.ClientConfigurationSystem.OnConfigRemoved(Object sender, InternalConfigEventArgs e) InnerException: This error occurs in a class written by the medium; I suspect that this class was written in the process of creating a model. Here is the code:
//------------------------------------------------------------------------------ // <auto-generated> // ΠΡΠΎΡ ΠΊΠΎΠ΄ ΡΠΎΠ·Π΄Π°Π½ ΠΏΠΎ ΡΠ°Π±Π»ΠΎΠ½Ρ. // // ΠΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΡ, Π²Π½ΠΎΡΠΈΠΌΡΠ΅ Π² ΡΡΠΎΡ ΡΠ°ΠΉΠ» Π²ΡΡΡΠ½ΡΡ, ΠΌΠΎΠ³ΡΡ ΠΏΡΠΈΠ²Π΅ΡΡΠΈ ΠΊ Π½Π΅ΠΏΡΠ΅Π΄Π²ΠΈΠ΄Π΅Π½Π½ΠΎΠΉ ΡΠ°Π±ΠΎΡΠ΅ ΠΏΡΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΡ. // ΠΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΡ, Π²Π½ΠΎΡΠΈΠΌΡΠ΅ Π² ΡΡΠΎΡ ΡΠ°ΠΉΠ» Π²ΡΡΡΠ½ΡΡ, Π±ΡΠ΄ΡΡ ΠΏΠ΅ΡΠ΅Π·Π°ΠΏΠΈΡΠ°Π½Ρ ΠΏΡΠΈ ΠΏΠΎΠ²ΡΠΎΡΠ½ΠΎΠΌ ΡΠΎΠ·Π΄Π°Π½ΠΈΠΈ ΠΊΠΎΠ΄Π°. // </auto-generated> //------------------------------------------------------------------------------ namespace AccessToClientsDB { using System; using System.Data.Entity; using System.Data.Entity.Infrastructure; public partial class clientdbEntities : DbContext { public clientdbEntities() : base("name=clientdbEntities") { } protected override void OnModelCreating(DbModelBuilder modelBuilder) { throw new UnintentionalCodeFirstException(); } public virtual DbSet<company> company { get; set; } public virtual DbSet<department> department { get; set; } public virtual DbSet<record> record { get; set; } public virtual DbSet<telephone> telephone { get; set; } } } Yes, I added the model to the class with the namespace AccessToClientsDB The exception is knocked out at this stage:
public clientdbEntities() : base("name=clientdbEntities") App.config
<?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" /> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> </configSections> <system.data> <DbProviderFactories> <remove invariant="MySql.Data.MySqlClient" /> <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /> </DbProviderFactories> </system.data> <!--<entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> <providers> <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> </providers> </entityFramework>--> <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" /> </providers> </entityFramework> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-6.9.8.0" newVersion="6.9.8.0" /> </dependentAssembly> </assemblyBinding> </runtime> <connectionStrings><add name="clientdbEntities" connectionString="metadata=res://*/clientdb.csdl|res://*/clientdb.ssdl|res://*/clientdb.msl;provider=MySql.Data.MySqlClient;provider connection string="server=localhost;user id=Andrew;password=150468;persistsecurityinfo=True;database=clientdb"" providerName="System.Data.EntityClient" /></connectionStrings></configuration> packages.config
<?xml version="1.0" encoding="utf-8"?> <packages> <package id="EntityFramework" version="6.1.3" targetFramework="net45" /> <package id="EntityFramework.ru" version="6.1.1" targetFramework="net45" /> <package id="MySql.Data" version="6.9.8" targetFramework="net45" /> <package id="MySql.Data.Entities" version="6.8.3.0" targetFramework="net45" /> <package id="MySql.Web" version="6.9.8" targetFramework="net45" /> </packages> The only point that, judging by all the forums, could be embarrassing is the different versions of EntityFramework, EntityFramework.ru in the references and in the package file. But I tried to change in the file with the same ones in the references and this did not help to correct the error. A little more confusing is that there are only EntitIES in the packages, but there is no EntitY, while the reference has Entity.EF6, and the EntitIES are not at all. I do not know what it depends on, but I added packages from NuGet, following the answer to this post: https://stackoverflow.com/questions/22031269/enable-entity-framework-6-for-mysql-c-in-winforms- Of-microsoft-visual-studio Although, if memory is not deceiving, I could add once, except for the EntitY package, also EntitIES.