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=&quot;server=localhost;user id=Andrew;password=150468;persistsecurityinfo=True;database=clientdb&quot;" 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.

    1 answer 1

    You also wrote in Russian: in the file C:\Users\Andrey\AppData\Local\GUI\GUI.vshost.exe_Url_ev1ciwvrswduwtnpzk5phoigckrk3o4m\1.0.0.0\user.config an unknown userSettings configuration userSettings .

    In the .NET configuration system is designed in such a way that if at least one section to the config is incomprehensible - all attempts to access the configuration fall.

    Delete the extra section from this file, or delete the user.config file completely.