无法识别的配置部分hibernate-configuration

本文关键字:hibernate-configuration 配置部 识别 | 更新日期: 2023-09-27 18:07:58

我在应用程序控制台中有以下配置文件:

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

我从一个虚拟应用程序(控制台应用程序)复制的nhibernate部分,它工作得很好。当我运行我的应用程序(一个稍微大一点的,有更多的类库项目涉及和引用),我得到以下异常:

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: 

我测试了与hibernate相同的Db连接的虚拟应用程序工作得很好。如果我删除nhibernate部分,应用程序的其余部分运行正常。谁能给我提示一下问题在哪里?(非hibernate版本是正确的)

谢谢,Tamas

无法识别的配置部分hibernate-configuration

你是否添加了所有必需的NHibernate引用到项目中?在我看来,应用程序无法加载NH配置节处理程序,因此无法识别整个<hibernate-configuration>块。