Hi,
I'm trying to write an app that can generate HBM files and DDL files for
any given assembly.
The code below looks like it should work, but it doesn't. I've highlighted the line that fails, and the exception is:
"System.TypeLoadException: Could not load type 'Northwind.Address, NHibernate, Version=1.0.2.0, Culture=neutral, PublicKeyToken=154fdcb44c4484fc', check that type and assembly names are correct"
Can anyone explain why it doesn't work, and what I can do to get around the problem?
Code:
''' <summary>
''' Generates the database schema to support the mappings
''' </summary>
''' <remarks></remarks>
Friend Sub generateSchema(ByVal assemblyFilePath As String, ByVal hbmDirectory As String, ByVal schemaOutputDirectory As String)
Dim _assembly As Reflection.Assembly = Reflection.Assembly.LoadFrom(assemblyFilePath)
' Certain NH properties need to be configured before the mappings can be loaded:
Dim _properties As New Hashtable
_properties.Add("hibernate.dialect", "NHibernate.Dialect.MsSql2000Dialect")
_properties.Add("hibernate.connection.driver_class", "NHibernate.Driver.SqlClientDriver")
_properties.Add("hibernate.connection.provider", "NHibernate.Connection.DriverConnectionProvider")
Dim _nhConfig As New NHibernate.Cfg.Configuration
_nhConfig.AddProperties(_properties)
' Load the Configuration with the mapping files:
Dim _hbmFiles() As String = IO.Directory.GetFiles(hbmDirectory, "*.hbm.xml")
For Each _hbmFile As String In _hbmFiles
_nhConfig.AddFile(_hbmFile) '<---- BANG!!
Next
' Perform the export:
Dim _exporter As New NHibernate.Tool.hbm2ddl.SchemaExport(_nhConfig)
Dim _outputFile As String = IO.Path.Combine(schemaOutputDirectory, _assembly.GetName.Name & ".sql")
_exporter.SetOutputFile(_outputFile)
_exporter.Execute(True, False, False, True)
End Sub