首页 > 解决方案 > 配置系统初始化 C# winforms 失败

问题描述

由于无法启动的配置系统错误,我的桌面应用程序无法运行。
错误是

System.TypeInitializationException:“'System.Data.SqlClient.SqlConnection' 的类型初始化程序引发了异常。” ConfigurationErrorsException:无法识别的配置部分 legacyUnhandledExceptionPolicy。(E:\visual studio projects\Windows form Application tutorials\Time Doctor App\Time Doctor App\bin\x86\Debug\Ezi Tasker 2.0.exe.Config 第18行)

我该如何解决这个问题?我做了很多更改,但它给了我一个错误类型的初始化程序抛出和异常。
这条线是Ezi Tasker 2.0.exe.Config line 18

这是我的App.config文件:

   <?xml version="1.0" encoding="utf-8"?>
   <configuration>
   <configSections>
   <section name="Signature" type="System.Configuration.IgnoreSectionHandler" />
  
  <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, 
  Version=4.0.0.0, Culture=neutral, PublicKeyToken=tooken" >
  <section name="Time_Doctor_App.Properties.Settings" 
  type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, 
  PublicKeyToken=token" allowExeDefinition="MachineToLocalUser" requirePermission="false" 
  />


</sectionGroup>
</configSections>
<system.windows.forms jitDebugging="true" />
<connectionStrings>
<add name="Conec" connectionString="conecstring"
  providerName="System.Data.SqlClient" />

 </connectionStrings>

<legacyUnhandledExceptionPolicy enabled='1'/>

<runtime>

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

  <dependentAssembly>

    <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="token" 
    culture="neutral" />

    <bindingRedirect oldVersion="0.0.0.0-4.0.5.0" newVersion="4.0.5.0" />

  </dependentAssembly>

  <dependentAssembly>

    <assemblyIdentity name="System.Buffers" publicKeyToken="token" culture="neutral" />

    <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />

  </dependentAssembly>

</assemblyBinding>

  </runtime>
 <userSettings>
<Time_Doctor_App.Properties.Settings>
  <setting name="User" serializeAs="String">
    <value />
  </setting>
  <setting name="Pass" serializeAs="String">
    <value />
  </setting>
</Time_Doctor_App.Properties.Settings>
</userSettings>
</configuration>

标签: c#winforms

解决方案


<legacyUnhandledExceptionPolicy enabled='1'/>元素必须是该元素的子元素<runtime>,因此将其移到那里:

    </connectionStrings>

    <runtime>
       <legacyUnhandledExceptionPolicy enabled='1'/>
       <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

推荐阅读