NHibernate - Unrecognized configuration section hibernate-configuration
I have the following configuration file in a application console:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
<section name="ConsoleApplication1.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup><applicationSettings>
<ConsoleApplication1.Properties.Settings>
<setting name="AppName" serializeAs="String">
<value>Simple Application</value>
</setting>
</ConsoleApplication1.Properties.Settings>
</applicationSettings>
<hibernate-configuration xmlns="urn:nhib开发者_如何学编程ernate-configuration-2.2">
<session-factory name="NHibernate.Test">
<property name="connection.driver_class">
NHibernate.Driver.SqlClientDriver
</property>
<property name="connection.connection_string">
Data Source=.\SQLEXPRESS;Initial Catalog=TravelAssistant;Integrated Security=True
</property>
<property name="adonet.batch_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="use_outer_join">true</property>
<property name="command_timeout">60</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
<property name="proxyfactory.factory_class">
NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu
</property>
</session-factory>
</hibernate-configuration>
</configuration>
The nhibernate section I haved copied from an dummy application (console application) where it worked just fine. When I run my app (a slightly bigger one with more class library projects involved and referenced) I get the following exception:
System.Configuration.ConfigurationErrorsException was unhandled
Message=Configuration system failed to initialize
Source=System.Configuration
BareMessage=Configuration system failed to initialize
Line=0
StackTrace:
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.RefreshConfig(String sectionName)
at System.Configuration.ConfigurationManager.RefreshSection(String sectionName)
at System.Configuration.ClientSettingsStore.ReadSettings(String sectionName, Boolean isUserScoped)
at System.Configuration.LocalFileSettingsProvider.GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties)
at System.Configuration.SettingsBase.GetPropertiesFromProvider(SettingsProvider provider)
at System.Configuration.SettingsBase.GetPropertyValueByName(String propertyName)
at System.Configuration.SettingsBase.get_Item(String propertyName)
at System.Configuration.ApplicationSettingsBase.GetPropertyValue(String propertyName)
at System.Configuration.ApplicationSettingsBase.get_Item(String propertyName)
at TravelAssistant.OnlineAPIs.Properties.Settings.get_HotelsAllStarsURL() in C:\Users\Tamas_Ionut\Documents\Visual Studio 2010\Projects\TravelAssistant\TravelAssistant.OnlineAPIs\Properties\Settings.Designer.cs:line 49
at TravelAssistant.OnlineAPIs.Implementations.CoreModels.Lodging.HotelLodgingProvider.ConstructURL(Location location, Decimal lowPrice, Decimal highPrice, List`1 numberOfStars, Int32 lowCustomerRating, Int32 highCustomerRating, DateTime checkIn, DateTime checkOut, Int32 numberOfAdults) in C:\Users\Tamas_Ionut\Documents\Visual Studio 2010\Projects\TravelAssistant\TravelAssistant.OnlineAPIs\Implementations\CoreModels\Lodging\HotelLodgingProvider.cs:line 77
at TravelAssistant.OnlineAPIs.Implementations.CoreModels.Lodging.HotelLodgingProvider.RetrieveHotels(Location location, Decimal lowPrice, Decimal highPrice, List`1 numberOfStars, Int32 lowCustomerRating, Int32 highCustomerRating, DateTime checkIn, DateTime checkOut, Int32 numberOfAdults) in C:\Users\Tamas_Ionut\Documents\Visual Studio 2010\Projects\TravelAssistant\TravelAssistant.OnlineAPIs\Implementations\CoreModels\Lodging\HotelLodgingProvider.cs:line 148
at ConsoleApplication1.Program.Main(String[] args) in C:\Users\Tamas_Ionut\Documents\Visual Studio 2010\Projects\TravelAssistant\ConsoleApplication1\Program.cs:line 23
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Configuration.ConfigurationErrorsException
Message=Unrecognized configuration section hibernate-configuration. (C:\Users\Tamas_Ionut\Documents\Visual Studio 2010\Projects\TravelAssistant\ConsoleApplication1\bin\Debug\ConsoleApplication1.vshost.exe.Config line 18)
Source=System.Configuration
BareMessage=Unrecognized configuration section hibernate-configuration.
Filename=C:\Users\Tamas_Ionut\Documents\Visual Studio 2010\Projects\TravelAssistant\ConsoleApplication1\bin\Debug\ConsoleApplication1.vshost.exe.Config
Line=18
StackTrace:
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
InnerException:
The dummy app where I haved tested the same Db connection with hibernate worked just fine. If I remove the nhibernate section the rest of the app runs just fine. Could someone give me a hint where is the issue? (the nhibernate versions are corect)
Thanks, Tamas
Did you add all the required NHibernate references to the project? This looks to me like the app can't load the NH configuration section handler and thus doesn't recognize the entire <hibernate-configuration>
block.
精彩评论