如何让 <configSections> <runtime> inside <configuration> 一起工作
How can I make <configSections> <runtime> inside <configuration> work together
这是我的 WPF 应用程序中的 app.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="XXX.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="XXX.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</sectionGroup>
</configSections>
<userSettings>...</userSettings>
<applicationSettings>...</applicationSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
运行 应用程序获取异常:
ConfigurationErrorsException: Only one element
allowed per config file and if present must be the first child of the
root element
如果我删除 <runtime>
部分应用程序运行良好 但会导致构建时间警告:
解决方案:
所以我的问题是 如何让 "configSections" "runtime" 在 "configuration" 中协同工作?
我没有看到一起使用 <runtime>
和 <configSections>
有任何问题(我做了 2用它做项目,两者都可以。
我不知道你用下面的部分配置了什么,也许你的问题就在里面:
<userSettings>...</userSettings>
<applicationSettings>...</applicationSettings>
尝试清理并重建解决方案。
这是我的 WPF 应用程序中的 app.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="XXX.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="XXX.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</sectionGroup>
</configSections>
<userSettings>...</userSettings>
<applicationSettings>...</applicationSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
运行 应用程序获取异常:
ConfigurationErrorsException: Only one element allowed per config file and if present must be the first child of the root element
如果我删除 <runtime>
部分应用程序运行良好 但会导致构建时间警告:
解决方案:
所以我的问题是 如何让 "configSections" "runtime" 在 "configuration" 中协同工作?
我没有看到一起使用 <runtime>
和 <configSections>
有任何问题(我做了 2用它做项目,两者都可以。
我不知道你用下面的部分配置了什么,也许你的问题就在里面:
<userSettings>...</userSettings>
<applicationSettings>...</applicationSettings>
尝试清理并重建解决方案。