Unrecognized configuration section applicationSettings in NHibernate
Asked Answered
C

1

9

I'm using fluent NHibernate.

I have an app.config file with few specific keys (applicationSettings and userSettings).

It seems that the nhibernate doesn't like these keys. As long as these keys exist in the file, the Fluently.Configure() fails and an exception with the message Unrecognized configuration section applicationSettings is thrown.

What can I do?

Here is the config file:

<?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>

Thank you!

Carrier answered 3/5, 2012 at 21:15 Comment(1)
Post your full config file. You probably just didn't format your config file properly.Everything
R
24

Your error Message is pretty much on-the-spot and has nothing to do with NHibernate: Configuration needs to know what ConfigSections it will provide, which you did not specify. This should not happen, did VS create the app.config for you?

<?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>

If you want further background on how Configuration works, read this for a start.

Rapprochement answered 8/5, 2012 at 8:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.