gpt4 book ai didi

c# - NHibernate 中无法识别的配置部分 applicationSettings

转载 作者:太空狗 更新时间:2023-10-29 17:34:23 25 4
gpt4 key购买 nike

我正在使用流畅的 NHibernate。

我有一个包含几个特定键(applicationSettings 和 userSettings)的 app.config 文件。

nhibernate 似乎不喜欢这些键。只要文件中存在这些键,Fluently.Configure() 就会失败,并会抛出消息无法识别的配置部分 applicationSettings 的异常。

我能做什么?

这是配置文件:

<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="MyDB" connectionString="Data Source=|DataDirectory|\MyDB.sdf" providerName="Microsoft.SqlServerCe.Client.3.5" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<applicationSettings>
<MyApp.Properties.Settings>
<setting name="ServerIp" serializeAs="String">
<value>127.0.0.1</value>
</setting>
<setting name="ServerPort" serializeAs="String">
<value>5678</value>
</setting>
<setting name="UseSSL" serializeAs="String">
<value>True</value>
</setting>
<setting name="WsUrl" serializeAs="String">
<value/>
</setting>
</MyApp.Properties.Settings>
</applicationSettings>
<userSettings>
<MyApp.Properties.Settings>
<setting name="User" serializeAs="String">
<value>test</value>
</setting>
<setting name="Password" serializeAs="String">
<value>test</value>
</setting>
</MyApp.Properties.Settings>
</userSettings>
</configuration>

谢谢!

最佳答案

你的错误消息几乎是现场的,与 NHibernate 无关:配置需要知道它将提供什么 ConfigSections,而你没有指定。这不应该发生,VS 是否为您创建了 app.config?

<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="MyApp.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="MyApp.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<!--...-->
</userSettings>
<applicationSettings>
<!--...-->
</applicationSettings>
</configuration>

如果您想进一步了解配置的工作原理,read this一开始。

关于c# - NHibernate 中无法识别的配置部分 applicationSettings,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10439438/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com