2016-03-03 4:25 GMT+00:00 Steve Lyle <[email protected]>:
> A) What error do you get when there is a typo in the XML mapping file's
> class-tab name-attribute value and you are using AddFile()?
> In other words when the name-attribute value != the name of the class
> in the class.cs file.
>
*log.txt:*
2016-03-03 18:57:46,594 [9] ERROR NHibernate.Cfg.Configuration - Could not
compile the mapping document:
C:\Users\oskar.berggren\Documents\Projects\nhibernate-core\Foo\NHStart\NHStart\Cat.hbm.xml
NHibernate.MappingException: Could not compile the mapping document:
C:\Users\oskar.berggren\Documents\Projects\nhibernate-core\Foo\NHStart\NHStart\Cat.hbm.xml
---> NHibernate.MappingException: persistent class NHStart.CatTYPO, NHStart
not found ---> System.TypeLoadException: Could not load type
'NHStart.CatTYPO' from assembly 'NHStart, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null'.
*Console.Error.WriteLine(ex.ToString());*
NHibernate.MappingException: Could not compile the mapping document:
C:\Users\os
kar.berggren\Documents\Projects\nhibernate-core\Foo\NHStart\NHStart\Cat.hbm.xml
---> NHibernate.MappingException: persistent class NHStart.CatTYPO, NHStart
not
found ---> System.TypeLoadException: Could not load type 'NHStart.CatTYPO'
from
assembly 'NHStart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
B) Without that typo, what error do you get when there is a typo in the
> string passed into AddFile()?
>
*log.txt:*2016-03-03 19:02:54,388 [10] ERROR NHibernate.Cfg.Configuration -
Could not compile the mapping document:
C:\Users\oskar.berggren\Documents\Projects\nhibernate-core\Foo\NHStart\NHStart\CatTYPO.hbm.xml
NHibernate.MappingException: Could not compile the mapping document:
C:\Users\oskar.berggren\Documents\Projects\nhibernate-core\Foo\NHStart\NHStart\CatTYPO.hbm.xml
---> System.IO.FileNotFoundException: Could not find file
'C:\Users\oskar.berggren\Documents\Projects\nhibernate-core\Foo\NHStart\NHStart\CatTYPO.hbm.xml'.
*Console.Error.WriteLine(ex.ToString());*
NHibernate.MappingException: Could not compile the mapping document:
C:\Users\os
kar.berggren\Documents\Projects\nhibernate-core\Foo\NHStart\NHStart\CatTYPO.hbm.
xml ---> System.IO.FileNotFoundException: Could not find file 'C:\Users\
oskar.be
rggren\Documents\Projects\nhibernate-core\Foo\NHStart\NHStart\CatTYPO.hbm.xml'.
> C) What if the typo is in the value of the assembly-attribute or the
> hibernate-mapping-tag and all else is without typos?
>
*log.txt:*
2016-03-03 19:06:03,631 [10] ERROR NHibernate.Cfg.Configuration - Could not
compile the mapping document:
C:\Users\oskar.berggren\Documents\Projects\nhibernate-core\Foo\NHStart\NHStart\Cat.hbm.xml
NHibernate.MappingException: Could not compile the mapping document:
C:\Users\oskar.berggren\Documents\Projects\nhibernate-core\Foo\NHStart\NHStart\Cat.hbm.xml
---> NHibernate.MappingException: persistent class NHStart.Cat, NHStartTYPO
not found ---> System.IO.FileNotFoundException: Could not load file or
assembly 'NHStartTYPO' or one of its dependencies. The system cannot find
the file specified.
*Console.Error.WriteLine(ex.ToString());*
NHibernate.MappingException: Could not compile the mapping document:
C:\Users\os
kar.berggren\Documents\Projects\nhibernate-core\Foo\NHStart\NHStart\Cat.hbm.xml
---> NHibernate.MappingException: persistent class NHStart.Cat, NHStartTYPO
not
found ---> System.IO.FileNotFoundException: Could not load file or assembly
'NHS
tartTYPO' or one of its dependencies. The system cannot find the file
specified.
> D) What if the typo is in the value of the namespace-attribute or the
> hibernate-mapping-tag and all else is without typos?
>
*log.txt:*
2016-03-03 19:08:29,147 [9] ERROR NHibernate.Cfg.Configuration - Could not
compile the mapping document:
C:\Users\oskar.berggren\Documents\Projects\nhibernate-core\Foo\NHStart\NHStart\Cat.hbm.xml
NHibernate.MappingException: Could not compile the mapping document:
C:\Users\oskar.berggren\Documents\Projects\nhibernate-core\Foo\NHStart\NHStart\Cat.hbm.xml
---> NHibernate.MappingException: persistent class NHStartTYPO.Cat, NHStart
not found ---> System.TypeLoadException: Could not load type
'NHStartTYPO.Cat' from assembly 'NHStart, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null'.
*Console.Error.WriteLine(ex.ToString());*
NHibernate.MappingException: Could not compile the mapping document:
C:\Users\os
kar.berggren\Documents\Projects\nhibernate-core\Foo\NHStart\NHStart\Cat.hbm.xml
---> NHibernate.MappingException: persistent class NHStartTYPO.Cat, NHStart
not
found ---> System.TypeLoadException: Could not load type 'NHStartTYPO.Cat'
from
assembly 'NHStart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
> E) How much of log4net helped you to deal with those errors?
>
Tremendously, but just catching and analyzing the exception in my own
application is also useful.
>
> I don't think this is what I had going on. Again I've gone through far to
> many iterations of this for me to say that at times perhaps it wasn't.
> But I did just find I can make a very easy demo of this.
>
> Try it yourself.
> VStudio 2015, new project / Web api / SPA.
> Add in nHibernate 4.0 & log4net 1.2.15
> Add config sections & configs to web.config.
>
> -- here is my openSessoin
> public static ISession OpenSession()
> {
> var cfg = new Configuration();
> cfg.Configure(); // nHibernate config is setup in Web.Config
> // AddFile() doesn't work. I don't care what they say.
> Everyone is setting the propertry of the XML mapping file to "Embedded
> Resource" for a reason.
> cfg.AddFile(@"C:\Users\slyle\Desktop\Steves NHibernate
> Playground\StevesnHibernatePlayground\MyFirstNHibernateSite\MyFirstNHibernateSite\Models\NHibernate\EmployeeList.hbm.xml");
> //cfg.AddFile(@"C:\Users\slyle\Desktop\Steves NHibernate
> Playground\MyFirstNHibernateSite\MyFirstNHibernateSite\Models\NHibernate\vEmployeeList.hbm.xml");
> //cfg.AddFile(@"C:\Users\slyle\Desktop\Steves NHibernate
> Playground\MyFirstNHibernateSite\MyFirstNHibernateSite\Models\NHibernate\spHireEveryone.hbm.xml");
> ISessionFactory ses = cfg.BuildSessionFactory();
> return ses.OpenSession();
> }
> ---
>
> I can make the error come and go as I please at run time by simply editing
> EmployeeList.hbm.xml; EmployeeList.hbm.xml is not an embedded resource.
> What errors do you get in all cases above?
> How much does log4net help you in this case?
>
I had VS2010 easily at hand, and I made my sample projects simple Console
Applications instead of web projects, but if you can "prove" that any of
those changes make a substantial difference to the exception message in
these cases you will indeed have found a very big compatibility issue (in
.Net itself, not in NHibernate).
Sometimes it can be a bit tricky to get log4net working in web projects,
due to difficulties getting the path to the log file correct (absolute
physical path is easiest for simple tests). But you haven't complained
about missing log files, so I assume you do get the file.
I'm attaching five different versions of my sample project - one is
working, the other four contains each of the typos you mention. Each of
them have a log-file in the bin-directory that already contains the full
output I've got.
*BEWARE that due to absolute paths the path to the mapping file will of
course be wrong in all five projects on your machine.*
/Oskar
>
>
>
>
>
>
>
> On Tuesday, March 1, 2016 at 5:55:02 PM UTC-5, Steve Lyle wrote:
>
>> This line of code:
>> cfg.AddFile(@"C:\Users\slyle\Documents\Visual Studio
>> 2015\Projects\Cat\Cat\Models\Cat.hbm.xml");
>>
>> Throws this error:
>> An exception of type 'NHibernate.MappingException' occurred
>> in NHibernate.dll but was not handled in user code
>> Additional information: Could not compile the mapping
>> document: C:\Users\slyle\Documents\Visual Studio
>> 2015\Projects\Cat\Cat\Models\Cat.hbm.xml
>>
>> Why?
>> It is as if AddFile() can't find *C:\Users\slyle\Documents\Visual Studio
>> 2015\Projects\Cat\Cat\Models\Cat.hbm.xml*
>> In fact, if I intentionally inject a typo in the path to the file I get
>> the same error.
>> However this line of code, immediately preceding AddFile(), doesn't have
>> any problems.
>> cfg.Configure(@"C:\Users\slyle\Documents\Visual Studio
>> 2015\Projects\Cat\Cat\Models\hibernate.cfg.xml");
>> I also find if I define the configuration in Web.config then there isn't
>> any trouble.
>> If I don't include the path-file literal in Configure() then the
>> hibernate.cfg.xml file will successfully be searched for and found in the
>> bin\ folder ~ kind of as a undocumented default.
>> But <mapping>.hbm.xml file/s are not afforded the same bin\ folder
>> courtesy.
>>
>> Understand this is code from the "QuickStart" taken right off of the
>> nHibernate website
>> and I have literally tried to many ways to get this to work that I'm
>> resorting to you, my 4th level of support.
>>
>> I understand by documentation and by construction nHibernate
>> confguration() has about 12 different ways to load mappings.
>> And I'd like to believe if one works then all others will work alike.
>> Personally I believe the "Embedded Resource" option is contrary to
>> flexibility and therefore contrary good application management.
>> Sadly, the "Embedded Resource" option seems to be the only way to make
>> nHibernate work.
>> And worse than all this is poor error reporting.
>> Shortcomings and underdevelopment all really buts enterprise adoption of
>> nHibernate into question.
>> Is this thing really meant to be something - or is it only a toy?
>>
>> -----
>> This is the mapping file:
>> <?xml version="1.0" encoding="utf-8" ?>
>> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
>> namespace="QuickStart" assembly="QuickStart">
>> <class name="Cat" table="Cat">
>> <!-- id name="Id"><column name="ID" sql-type="int" not-null="true"
>> /><generator class="identity" /></id -->
>> <id name="Id"><column name="CatId" sql-type="char(32)"
>> not-null="true"/><generator class="uuid.hex" /></id>
>> <property name="Name"><column name="Name" length="16" not-null="true"
>> /></property>
>> <property name="Sex" />
>> <property name="Weight" />
>> </class>
>> </hibernate-mapping>
>> -----
>>
>> -----
>> This is the c# model:
>> using System;
>> using System.Collections.Generic;
>> using System.Linq;
>> using System.Web;
>>
>> namespace QuickStart
>> {
>> public class Cat
>> {
>> private string id;
>> private string name;
>> private char sex;
>> private float weight;
>>
>> public Cat(){}
>>
>> public virtual string Id { get { return id; } set { id = value; }
>> }
>> public virtual string Name { get { return name; } set { name =
>> value; } }
>> public virtual char Sex { get { return sex; } set { sex = value;
>> } }
>> public virtual float Weight { get { return weight; } set { weight
>> = value; } }
>> }
>> }
>> -----
>>
>>
>> -----
>> And this is the table DDL:
>> CREATE TABLE [dbo].[Cat](
>> [CatId] [char](32) NOT NULL,
>> [Name] [nvarchar](16) NOT NULL,
>> [Sex] [nchar](1) NULL,
>> [Weight] [real] NULL,
>> CONSTRAINT [PK_Cat] PRIMARY KEY CLUSTERED
>> (
>> [CatId] ASC
>> )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY =
>> OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
>> ) ON [PRIMARY]
>> -----
>>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/nhusers.
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.