2016-03-01 15:49 GMT+00:00 Steve Lyle <ssl...@gmail.com>: > 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 >
"not handled in user code" tells us that you haven't implement code to properly catch and PRINT the exception information. > Additional information: Could not compile the mapping > document: C:\Users\slyle\Documents\Visual Studio > 2015\Projects\Cat\Cat\Models\Cat.hbm.xml > I'm not sure what produces that line, but it's not the full information that NHibernate generates. > > 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. > That is just a guess, because you don't show the full error message. It could very well be "file not found" in one case and some syntax error in the mapping file in the other case. Like I wrote in the other thread you MUST look at the type and message of ALL InnerExceptions. The property Exception.InnerException is a very fundamental concept in understanding .Net expections, sadly many seem to miss this and only read the outer exception text. Generally the top-most exception will indicate what high-level operation failed, while the InnerExceptions will gradually reveal more detail on what exactly went wrong. I've checked the NHibernate source code, and there appears to be exactly TWO places where a MappingException is thrown with the "Could not compile the mapping document"-message. In both cases, the exception is thrown using code similar to this: catch (Exception e) { var message = documentFileName == null ? "Could not compile deserialized mapping document." : "Could not compile the mapping document: " + documentFileName; LogAndThrow(new MappingException(message, e)); // <--- Notice here how the underlying exception is passed along. } And it is the exception "e", which will show up as InnerException on the MappingException, and this will tell you in more detail what exactly went wrong. Hint - your code should look like this: try { your configuration and mapping code goes here } catch (Exception ex) { // ex.ToString() will recursively include the message and stacktrace from all inner exceptions. // Assuming your program runs from a command prompt. // Alternatively, put a breakpoint on the next line and explore the // excepton and inner exceptions with the Visual Studio exception helper. Console.WriteLine(ex.ToString()); Console.ReadLine(); } > 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. > Let's find the real problem before jumping to conclusions. > And worse than all this is poor error reporting. > NHibernate _generates_ a lot of debug and error information. The error _reporting_ is up to you as application developer - NHibernate can't know if you want to stick it in a log file, show a dialog, print to console, or whatever. However, NHibernate will log everything to log4net, so you can just enable that in your project to get very extensive information (see my reply in your other thread). /Oskar -- 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 nhusers+unsubscr...@googlegroups.com. To post to this group, send email to nhusers@googlegroups.com. Visit this group at https://groups.google.com/group/nhusers. For more options, visit https://groups.google.com/d/optout.