1

NHibernate を実装するプロジェクトがあります。プロジェクトは Visual Studio 2010 を搭載したマシンで正常に動作します。そのプロジェクトを Visual Studio 2012 にインポートすると、 NHibernate.MappingExceptionが発生します。

.hbm.xml は埋め込みリソースとして設定され、出力ディレクトリへのコピーはすべての .hbm.xml ファイルに対して常にコピーとして設定されます。

プロジェクトはVS 2010で実行されるため、マッピングの問題がどのように発生するかわかりません。


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="dialect">NHibernate.Dialect.MsSqlCeDialect</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlServerCeDriver</property>
    <property name="connection.connection_string">Data Source=FirstSample.sdf</property>
    <property name="show_sql">true</property>
  </session-factory>
</hibernate-configuration>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="HibernateExample" namespace="HibernateExample.Domain" >
  <class name="Grains" table="Products">
    <id name="Id" type="integer">
      <generator class="identity"/>
    </id>
    <property name="Name" type="string"/>
    <property name="Category" type="string"/>
    <property name="Discontinued" />
  </class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="HibernateExample" namespace="HibernateExample.Domain" >
  <class name="Dairy" table="Products">
    <id name="Id" type="integer">
      <generator class="identity"/>
    </id>
    <property name="Name" type="string"/>
    <property name="Category" type="string"/>
    <property name="Discontinued" />
  </class>
</hibernate-mapping>

app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
  </configSections>
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
    <session-factory>
      <property name="connection.driver_class"> NHibernate.Driver.SqlServerCeDriver</property>
        <property name="dialect">NHibernate.Dialect.MsSqlCeDialect</property>
      <property name="connection.connection_string">Data Source=FirstSample.sdf;</property>
      <property name="show_sql">true</property>
    </session-factory>
  </hibernate-configuration>


  <connectionStrings>
        <add name="testconnectionstring"
            connectionString="Data Source=|DataDirectory|\FirstSample.sdf;Integrated Security=True"
            providerName="Microsoft.SqlServerCe.Client.3.5" />
    </connectionStrings>

  <runtime>
    <assemblyBinding xmlns="urnchemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845DCD8080CC91" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-9.0.242.0" newVersion="3.5.0.0"/>
      </dependentAssembly>
    </assemblyBinding>

  </runtime>
</configuration>

A first chance exception of type 'System.TypeLoadException' occurred in mscorlib.dll

A first chance exception of type 'System.TypeLoadException' occurred in NHibernate.dll

A first chance exception of type 'NHibernate.MappingException' occurred in NHibernate.dll

A first chance exception of type 'NHibernate.MappingException' occurred in NHibernate.dll

A first chance exception of type 'NHibernate.MappingException' occurred in NHibernate.dll

A first chance exception of type 'NHibernate.MappingException' occurred in NHibernate.dll

Error: NHibernate.MappingException: Could not compile the mapping document: HibernateExample.Domain.Dairy.hbm.xml ---> NHibernate.MappingException: persistent class HibernateExample.Domain.Dairy, HibernateExample not found ---> System.TypeLoadException: Could not load type 'HibernateExample.Domain.Dairy' from assembly 'HibernateExample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type)

at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)

at NHibernate.Util.ReflectHelper.TypeFromAssembly(AssemblyQualifiedTypeName name, Boolean throwOnError) in p:\nhibernate-core\src\NHibernate\Util\ReflectHelper.cs:line 308

at NHibernate.Util.ReflectHelper.ClassForName(String name) in p:\nhibernate-core\src\NHibernate\Util\ReflectHelper.cs:line 181

at NHibernate.Cfg.XmlHbmBinding.Binder.ClassForFullNameChecked(String fullName, String errorMessage) in p:\nhibernate-core\src\NHibernate\Cfg\XmlHbmBinding\Binder.cs:line 99

--- End of inner exception stack trace ---

at NHibernate.Cfg.XmlHbmBinding.Binder.ClassForFullNameChecked(String fullName, String errorMessage) in p:\nhibernate-core\src\NHibernate\Cfg\XmlHbmBinding\Binder.cs:line 105

at NHibernate.Cfg.XmlHbmBinding.Binder.ClassForNameChecked(String name, Mappings mappings, String errorMessage) in p:\nhibernate-core\src\NHibernate\Cfg\XmlHbmBinding\Binder.cs:line 117

at NHibernate.Cfg.XmlHbmBinding.ClassBinder.BindClass(IEntityMapping classMapping, PersistentClass model, IDictionary`2 inheritedMetas) in p:\nhibernate-core\src\NHibernate\Cfg\XmlHbmBinding\ClassBinder.cs:line 32

at NHibernate.Cfg.XmlHbmBinding.RootClassBinder.Bind(HbmClass classSchema, IDictionary`2 inheritedMetas) in p:\nhibernate-core\src\NHibernate\Cfg\XmlHbmBinding\RootClassBinder.cs:line 21

at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddRootClasses(HbmClass rootClass, IDictionary`2 inheritedMetas) in p:\nhibernate-core\src\NHibernate\Cfg\XmlHbmBinding\MappingRootBinder.cs:line 84

at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddEntitiesMappings(HbmMapping mappingSchema, IDictionary`2 inheritedMetas) in p:\nhibernate-core\src\NHibernate\Cfg\XmlHbmBinding\MappingRootBinder.cs:line 42

at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.Bind(HbmMapping mappingSchema) in p:\nhibernate-core\src\NHibernate\Cfg\XmlHbmBinding\MappingRootBinder.cs:line 31

at NHibernate.Cfg.Configuration.AddDeserializedMapping(HbmMapping mappingDocument, String documentFileName) in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 523

--- End of inner exception stack trace ---

at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception) in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 342

at NHibernate.Cfg.Configuration.AddDeserializedMapping(HbmMapping mappingDocument, String documentFileName) in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 530

at NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc) in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 500

at NHibernate.Cfg.Configuration.ProcessMappingsQueue() in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 1865

at NHibernate.Cfg.Configuration.AddDocumentThroughQueue(NamedXmlDocument document) in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 1857

at NHibernate.Cfg.Configuration.AddXmlReader(XmlReader hbmReader, String name) in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 1850

at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name) in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 652

at NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly) in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 690

at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly) in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 769

at HibernateExample.NHibernateTest.NHibernateHelper.OpenSession() in c:\Users\Fabian\Documents\Visual Studio 2010\Projects\NHibernate\HibernateExample\NHibernateTest\NHibernateHelper.cs:line 31

Error: Could not compile the mapping document: HibernateExample.Domain.Dairy.hbm.xml

A first chance exception of type 'System.NullReferenceException' occurred in HibernateExample.exe
4

1 に答える 1

2

必要なすべての情報を含む内部例外は次のとおりです。

エラー: NHibernate.MappingException: マッピング ドキュメントをコンパイルできませんでした: HibernateExample.Domain.Dairy.hbm.xml ---> NHibernate.MappingException: 永続クラス HibernateExample.Domain.Dairy、HibernateExample が見つかりません ---> System.TypeLoadException: 可能性がありますアセンブリ 'HibernateExample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' からタイプ 'HibernateExample.Domain.Dairy' をロードしません。

Factory 構成中に、NHibernate は 3 番目 (質問の上から) を含むすべての埋め込みリソースを読み取ります。

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" 
  assembly="HibernateExample" 
  namespace="HibernateExample.Domain" >
  <class name="Dairy" table="Products">

したがって、問題は明確です。利用可能なクラスがありませHibernateExample.Domain.Dairyん (デプロイされていない、タイプミス、またはネームスペースが正しくありません)。良いニュースまたはメッセージは、マッピングが見つかり、解析されたことです...

アプリケーションがマップされたクラスにアクセスできることを確認してください

于 2013-01-29T05:10:55.280 に答える