c# - 配置系统初始化 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>
解决方案
该<legacyUnhandledExceptionPolicy enabled='1'/>
元素必须是该元素的子元素<runtime>
,因此将其移到那里:
</connectionStrings>
<runtime>
<legacyUnhandledExceptionPolicy enabled='1'/>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
推荐阅读
- typescript - 从打字稿的目录中实例化所有类
- reactjs - Yarn 3.x PNP typescript CRA eslint 不适用于 VSCode
- javascript - 如何检查剧作家的回应
- java - 错误:二元运算符 '>=' 的错误操作数类型“else if (bmi <=18.5 >=25.0)”
- python - pygame 在条件下自动重复声音
- c++ - 保持函数参数的 consteval-ness
- python - 跨多个维度重复一维数组中的值
- javascript - React路由器dom更改url,不渲染组件
- python - 我无法在 Windows 11 上安装 pyaudio?
- flutter - Flutter body 可能正常完成,导致返回 'null',但返回类型是潜在的不可为空的类型