我正在使用流利的NHibernate。
我有一个app.config文件,其中包含很少的特定键(applicationSettings和userSettings)。
似乎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>
谢谢!
答案 0 :(得分:21)
您的错误消息几乎是现场的,与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>
如果您想了解有关配置如何工作的更多背景信息,请{/ 3}}开始。