9

我正在使用流利的 NHibernate。

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

似乎 nhibernate 不喜欢这些键。只要文件中存在这些键,Fluently.Configure() 就会失败,并抛出带有 Unrecognized configuration section 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>

谢谢!

4

1 回答 1

23

您的错误消息几乎是现场的,与 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>

如果您想进一步了解 Configuration 的工作原理,请先阅读本文

于 2012-05-08T08:12:28.570 回答