title: Object does not match target type.. Exception occured getter
body: <p>I have a huge problem! I keep getting an exception when mapping an abstract class with multiple union-subclasses in nhibernate.
  When I use only one union-subclass I dont get any error and everything works fine. When I use more subclasses this error occures:</p>
  
  <blockquote>
    <p>[TargetException: Object does not match target type.]
           System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target) +10909543
           System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +115
           System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +54
           System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture) +61
           System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index) +19
           NHibernate.Properties.BasicGetter.Get(Object target) +99</p>
    
    <p>[PropertyAccessException: Exception occurred getter of MedControlWeb.Models.Logs.Log.Code]
           NHibernate.Properties.BasicGetter.Get(Object target) +183
           NHibernate.Engine.UnsavedValueFactory.GetUnsavedIdentifierValue(String unsavedValue, IGetter identifierGetter, IType identifierType, ConstructorInfo constructor) +160
           NHibernate.Tuple.PropertyFactory.BuildIdentifierProperty(PersistentClass mappedEntity, IIdentifierGenerator generator) +200
           NHibernate.Tuple.Entity.EntityMetamodel..ctor(PersistentClass persistentClass, ISessionFactoryImplementor sessionFactory) +775
           NHibernate.Persister.Entity.AbstractEntityPersister..ctor(PersistentClass persistentClass, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory) +835
           NHibernate.Persister.Entity.UnionSubclassEntityPersister..ctor(PersistentClass persistentClass, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, IMapping mapping) +220
           NHibernate.Persister.PersisterFactory.CreateClassPersister(PersistentClass model, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, IMapping cfg) +369
           NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners) +2199
           NHibernate.Cfg.Configuration.BuildSessionFactory() +181</p>
  </blockquote>
  
  <p>My hbm file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                     assembly="MedControlWeb"
                     namespace="MedControlWeb.Models.Logs"&gt;
  
    &lt;class name="Log" abstract="true" lazy="false"&gt;
      &lt;id name="Code" column="code"&gt;
        &lt;generator class="hilo"/&gt;
      &lt;/id&gt;
  
      &lt;property name="Description" column="description"/&gt;
      &lt;property name="User" column="user"/&gt;
      &lt;property name="Timestamp" column="timestamp"/&gt;
      &lt;property name="Action" column="action"/&gt;
  
      &lt;union-subclass name="SettingsLog" table="settings_log" lazy="false"&gt;
      &lt;/union-subclass&gt;
  
      &lt;union-subclass name="JobLog" table="job_log" lazy="false"&gt;
      &lt;/union-subclass&gt;
  
    &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>My abstract super class:</p>
  
  <pre><code>public class Log
  {
      public int Code { get; set; }
      public DateTime Timestamp { get; set; }
      public MedControlWeb.Enums.Action Action { get; set; }
      public string Description { get; set; }
      public int User { get; set; }
  }
  </code></pre>
  
  <p>One of the subclasses:</p>
  
  <pre><code>public class SettingsLog : Log
  {        
  }
  </code></pre>
  
  <p>Where am I going wrong?</p>
  
  <p>Edit:
  What can I do to solve this error? I dont see how I can fix it since I have proper get methods?</p>