title: C# NHibernate MappingException was unhandled
body: <p>I'm new to NHibernate and I wanted to create a simple project to start using it. I followed this tutorial <a href="http://www.youtube.com/watch?v=FkmFI736wMU" rel="nofollow">http://www.youtube.com/watch?v=FkmFI736wMU</a> to set up the NHibernate files and configuration. Unlike the link, I use Mysql.
  I can't run the program because I get a Mapping Exception (Could not compile the mapping document: catsHibernate.Code.Cat.hbm.xml) as soon as I create a configuration object. Here is my code, Cat is a simple class with gets and sets only.</p>
  
  <p>App.config</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
    &lt;configSections&gt;
      &lt;section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/&gt;
    &lt;/configSections&gt;
  
    &lt;hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"&gt;
      &lt;session-factory&gt;
        &lt;property name="connection.provider"&gt;NHibernate.Connection.DriverConnectionProvider&lt;/property&gt;
        &lt;property name="dialect"&gt;NHibernate.Dialect.MySQLDialect&lt;/property&gt;
        &lt;property name="connection.driver_class"&gt;NHibernate.Driver.MySqlDataDriver&lt;/property&gt;
        &lt;property name="connection.connection_string"&gt;Server=localhost;Database=catsdb;User ID=root;Password=root&lt;/property&gt;
  
        &lt;mapping assembly="catsHibernate"/&gt;
      &lt;/session-factory&gt;
    &lt;/hibernate-configuration&gt;
  &lt;startup&gt;&lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/&gt;&lt;/startup&gt;&lt;/configuration&gt;
  </code></pre>
  
  <p>Cat.hbm.xml</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="catsHibernate.code" namespace="catsHibernate.code"&gt;
  
    &lt;class name="Cat" table="cats"&gt;
      &lt;id name="id" column="id" type="String"&gt;&lt;/id&gt;
  
      &lt;property name="name" type="String"&gt;
        &lt;column name="name" length="45" sql-type="varchar" not-null="true"/&gt;
      &lt;/property&gt;
  
      &lt;property name="sex" column="sex" not-null="true" update="false"/&gt;
  
      &lt;property name="weight" column="weight" not-null="true"/&gt;
  
    &lt;/class&gt;
  
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>Program.cs</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          Configuration cfg = new Configuration().Configure();
  
          ISessionFactory sessionFactory = cfg.BuildSessionFactory();
  
          //ISessionFactory sessionFactory = new Configuration().Configure().BuildSessionFactory();
  
          ISession session = sessionFactory.OpenSession();
  
          ITransaction tx1 = session.BeginTransaction();
  
          Cat c1 = new Cat();
          c1.Id = "cat1";
          c1.Name = "Fluffy";
          c1.Sex = 'f';
          c1.Weight = 3.2F;
  
          Cat c2 = new Cat();
          c2.Id = "cat2";
          c2.Name = "Mittens";
          c2.Sex = 'm';
          c2.Weight = 4.3F;
  
          try
          {
              session.Save(c1);
              session.Save(c2);
              tx1.Commit();
          }
          catch (Exception ex)
          {
              tx1.Rollback();
              throw ex;
          }
  
          ITransaction tx2 = session.BeginTransaction();
  
          var cats = session.CreateQuery("FROM cats").List&lt;Cat&gt;();
  
          foreach (Cat c in cats)
          {
              Console.WriteLine(c.Name);
          }
  
          tx2.Commit();
          session.Close();
  
      }
  }
  </code></pre>
  
  <p>Cat.hbm.xml is embedded resource. Like I said, I get a mapping exception as soon as I create a configuration object ->  Configuration cfg = new Configuration().Configure(); .</p>
  
  <p>What am I doing wrong here?</p>
  
  <p>Edit - Stack Trace</p>
  
  <pre><code>NHibernate.MappingException was unhandled
    HResult=-2146232832
    Message=Could not compile the mapping document: catsHibernate.Code.Cat.hbm.xml
    Source=NHibernate
    StackTrace:
         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 NHibernate.Cfg.Configuration.AddAssembly(String assemblyName) in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 752
         at NHibernate.Cfg.Configuration.DoConfigure(ISessionFactoryConfiguration factoryConfiguration) in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 1574
         at NHibernate.Cfg.Configuration.Configure() in p:\nhibernate-core\src\NHibernate\Cfg\Configuration.cs:line 1433
         at catsHibernate.Program.Main(String[] args) in c:\Users\Cátia\Documents\Visual Studio 2012\Projects\catsHibernate\catsHibernate\Code\Program.cs:line 15
         at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
         at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
         at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
         at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
         at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
         at System.Threading.ThreadHelper.ThreadStart()
    InnerException: NHibernate.MappingException
         HResult=-2146232832
         Message=persistent class catsHibernate.Code.Cat, catsHibernate.Code not found
         Source=NHibernate
         StackTrace:
              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
         InnerException: System.IO.FileNotFoundException
              HResult=-2147024894
              Message=Could not load file or assembly 'catsHibernate.Code' or one of its dependencies. O sistema não conseguiu localizar o ficheiro especificado.
              Source=mscorlib
              FileName=catsHibernate.Code
              FusionLog==== Pre-bind state information ===
  LOG: DisplayName = catsHibernate.Code
   (Partial)
  WRN: Partial binding information was supplied for an assembly:
  WRN: Assembly Name: catsHibernate.Code | Domain ID: 1
  WRN: A partial bind occurs when only part of the assembly display name is provided.
  WRN: This might result in the binder loading an incorrect assembly.
  WRN: It is recommended to provide a fully specified textual identity for the assembly,
  WRN: that consists of the simple name, version, culture, and public key token.
  WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
  LOG: Appbase = file:///C:/Users/Cátia/documents/visual studio 2012/Projects/catsHibernate/catsHibernate/bin/Debug/
  LOG: Initial PrivatePath = NULL
  Calling assembly : NHibernate, Version=3.3.1.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4.
  ===
  LOG: This bind starts in default load context.
  LOG: Using application configuration file: C:\Users\Cátia\documents\visual studio 2012\Projects\catsHibernate\catsHibernate\bin\Debug\catsHibernate.vshost.exe.Config
  LOG: Using host configuration file: 
  LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
  LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
  LOG: The same bind was seen before, and was failed with hr = 0x80070002.
  
          StackTrace:
               at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark&amp; stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
               at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark&amp; stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
               at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark&amp; stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection)
               at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark&amp; stackMark, Boolean forIntrospection)
               at System.Reflection.Assembly.Load(String assemblyString)
               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
          InnerException: 
  </code></pre>