Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate "Could not determine type for X" error
    primarykey
    data
    text
    <p>After upgrading the NHibernate and FluentNHibernate DLLs in a project, I'm now getting a "Could not determine type for: MyApp.Domain.Entities.AppCategory" exception thrown when initializing the SessionFactory. The only change in my code was tweaking the implementation of ForeignKeyConvention to override the <code>GetKeyName ( Member member, Type type )</code> abstract method, instead of <code>GetKeyName ( PropertyInfo property, Type type )</code>.</p> <p>The upgraded DLLs were from 1.0.0.593 to 1.1.0.685 for FluentNHibernate, and from 2.1.0.4000 to 2.1.2.4000 for NHibernate. Part of the difficulty in finding a solution is the old age of the NHibernate version we're using, but that can't be changed, at least for now.</p> <p>I posted the full exception and all relevant code and configuration below. I apologize for the length, but I have no idea where the problem might be.</p> <p><strong>Full Exception</strong></p> <pre><code>FluentNHibernate.Cfg.FluentConfigurationException : An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail. ----&gt; FluentNHibernate.Cfg.FluentConfigurationException : An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail. ----&gt; NHibernate.MappingException : Could not compile the mapping document: (XmlDocument) ----&gt; NHibernate.MappingException : Could not determine type for: MyApp.Domain.Entities.AppCategory, MyApp.Domain, Version=1.0.0.76, Culture=neutral, PublicKeyToken=null, for columns: NHibernate.Mapping.Column(AppCategory) at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs: line 98 at MyFramework.App.DataAccess.NHibernate.Databases.BaseDatabase.CreateSessionFactory() in C:\WIP\VSProjects\MyFramework\src\App\DataAccess\NHibernate\Databases\BaseDatabase.cs: line 115 at MyFramework.App.DataAccess.NHibernate.Databases.BaseDatabase.Init() in C:\WIP\VSProjects\MyFramework\src\App\DataAccess\NHibernate\Databases\BaseDatabase.cs: line 100 at MyApp.DataAccess.SmartStudioUserUnitOfWork.&lt;.ctor&gt;b__0() in SmartStudioUserUnitOfWork.cs: line 28 at MyFramework.App.DataAccess.NHibernate.UnitOfWork`1.Create(FlushMode flushMode) in C:\WIP\VSProjects\MyFramework\src\App\DataAccess\NHibernate\UnitOfWork.cs: line 72 at MyFramework.App.DataAccess.NHibernate.UnitOfWork`1..ctor(Func`1 getBaseDatabase) in C:\WIP\VSProjects\MyFramework\src\App\DataAccess\NHibernate\UnitOfWork.cs: line 37 at MyApp.DataAccess.SmartStudioUserUnitOfWork..ctor() in SmartStudioUserUnitOfWork.cs: line 17 at MyApp.DataAccess.Test.SmartStudioUserDaoTest.create_dao() in SmartStudioUserDaoTest.cs: line 20 --FluentConfigurationException at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs: line 119 at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs: line 93 --MappingException at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception) at NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc) at NHibernate.Cfg.Configuration.ProcessMappingsQueue() at NHibernate.Cfg.Configuration.AddDocumentThroughQueue(NamedXmlDocument document) at NHibernate.Cfg.Configuration.AddXmlReader(XmlReader hbmReader, String name) at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name) at NHibernate.Cfg.Configuration.AddDocument(XmlDocument doc, String name) at NHibernate.Cfg.Configuration.AddDocument(XmlDocument doc) at FluentNHibernate.PersistenceModel.Configure(Configuration cfg) in d:\Builds\FluentNH\src\FluentNHibernate\PersistenceModel.cs: line 262 at FluentNHibernate.Automapping.AutoPersistenceModel.Configure(Configuration configuration) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoPersistenceModel.cs: line 170 at FluentNHibernate.Cfg.AutoMappingsContainer.Apply(Configuration cfg) in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\AutoMappingsContainer.cs: line 84 at FluentNHibernate.Cfg.MappingConfiguration.Apply(Configuration cfg) in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\MappingConfiguration.cs: line 56 at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs: line 110 --MappingException at NHibernate.Mapping.SimpleValue.get_Type() at NHibernate.Cfg.XmlHbmBinding.ClassBinder.BindProperty(XmlNode node, Property property, IDictionary`2 inheritedMetas) at NHibernate.Cfg.XmlHbmBinding.ClassBinder.CreateProperty(IValue value, String propertyName, String className, XmlNode subnode, IDictionary`2 inheritedMetas) at NHibernate.Cfg.XmlHbmBinding.ClassBinder.BindJoin(XmlNode node, Join join, IDictionary`2 inheritedMetas) at NHibernate.Cfg.XmlHbmBinding.ClassBinder.PropertiesFromXML(XmlNode node, PersistentClass model, IDictionary`2 inheritedMetas, UniqueKey uniqueKey, Boolean mutable, Boolean nullable, Boolean naturalId) at NHibernate.Cfg.XmlHbmBinding.RootClassBinder.Bind(XmlNode node, HbmClass classSchema, IDictionary`2 inheritedMetas) at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddRootClasses(XmlNode parentNode, IDictionary`2 inheritedMetas) at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.Bind(XmlNode node) at NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc) </code></pre> <p><strong>Fluent Configuration</strong></p> <pre><code>sessionFactory = fluentConfiguration .Mappings(m =&gt; m.AutoMappings.Add( AutoMap.AssemblyOf&lt;Application&gt;().Conventions .Add&lt;CustomForeignKeyConvention&gt;())) .ExposeConfiguration(new SchemaExport(config).Create(true, false)) .BuildSessionFactory(); public class CustomForeignKeyConvention : ForeignKeyConvention { protected override string GetKeyName ( Member member, Type type ) { if (member == null) { return type.Name + "Id"; } return member.Name + "Id"; } } </code></pre> <p><strong>Domain classes</strong></p> <pre><code>public class Application { public virtual int Id { get; set; } public virtual string FriendlyName { get; set; } public virtual AppCategory AppCategory { get; set; } } public class AppCategory { public virtual int Id { get; private set; } public virtual string CategoryName { get; set; } } </code></pre> <p><strong>Database Table Definitions</strong></p> <pre><code>CREATE TABLE [dbo].[Application]( [Id] [int] IDENTITY(1,1) NOT NULL, [FriendlyName] [varchar](255) NOT NULL, [AppCategoryId] [int] NOT NULL, CONSTRAINT [PK_Application] PRIMARY KEY CLUSTERED ([Id] ASC) ) GO ALTER TABLE [dbo].[Application] WITH CHECK ADD CONSTRAINT [FK_Application_AppCategory] FOREIGN KEY([AppCategoryId]) REFERENCES [dbo].[AppCategory] ([Id]) GO ALTER TABLE [dbo].[Application] CHECK CONSTRAINT [FK_Application_AppCategory] GO CREATE TABLE [dbo].[AppCategory]( [Id] [int] IDENTITY(1,1) NOT NULL, [CategoryName] [nvarchar](50) NOT NULL, CONSTRAINT [PK_AppCategory] PRIMARY KEY CLUSTERED ([Id] ASC) ) </code></pre> <p><strong>Fluent NHibernate Mapping</strong></p> <pre><code>public class ApplicationMappingOverride : IAutoMappingOverride&lt;Application&gt; { public void Override(AutoMapping&lt;Application&gt; mapping) { mapping.Table("Application"); mapping.Id(x =&gt; x.Id); mapping.Map(x =&gt; x.FriendlyName); mapping.Join("AppCategory", x =&gt; x.Map(y =&gt; y.AppCategory)); } } </code></pre> <p><strong>Mapping XML (pulled from Fluent NHibernate log message):</strong></p> <pre><code>&lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import="true" default-cascade="none" default-lazy="true"&gt; &lt;class xmlns="urn:nhibernate-mapping-2.2" mutable="true" name="MyApp.Domain.Entities.Application, MyApp.Domain, Version=1.0.0.76, Culture=neutral, PublicKeyToken=null" table="Application"&gt; &lt;id name="Id" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"&gt; &lt;column name="Id" /&gt; &lt;generator class="identity" /&gt; &lt;/id&gt; &lt;property name="FriendlyName" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"&gt; &lt;column name="FriendlyName" /&gt; &lt;/property&gt; &lt;join table="AppCategory"&gt; &lt;key&gt; &lt;column name="ApplicationId" /&gt; &lt;/key&gt; &lt;property name="AppCategory" type="MyApp.Domain.Entities.AppCategory, MyApp.Domain, Version=1.0.0.76, Culture=neutral, PublicKeyToken=null"&gt; &lt;column name="AppCategory" /&gt; &lt;/property&gt; &lt;/join&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload