These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: cfg.AddAssembly("NHibernate.Examples"); fails
PostPosted: Fri Apr 13, 2007 3:04 pm 
Newbie

Joined: Fri Apr 13, 2007 2:50 pm
Posts: 3
Location: Cincinnati Ohio
This should be simple.
I'm newish to nHibernate.
I attempted the example shown in the Quick Start.
My implimentation is on MS Visual 2005 - Windows GUI app.
See code snip & xml file below.

The problem: 'cfg.AddAssembly("NHibernate.Examples");' throws: 'MappingException was unhandled' and 'Could not add assembly NHibernate.Examples

But I can't find anything supporting this newbee issue.

--- code snip start ---
    using System;
    using System.Collections.Generic;
    using System.Windows.Forms;

    using NHibernate;
    using NHibernate.Cfg;

    using NHibernate.Examples.QuickStart;

    namespace WindowsApplication1
    {
    static class Program
    {
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
    User _user = new User();

    Configuration cfg = new Configuration();
    cfg.AddAssembly("NHibernate.Examples");
    ISessionFactory factory = cfg.BuildSessionFactory();
    ISession session = factory.OpenSession();
--- code snip end ---

--- User.hbm.xml start ---
    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
    <class name="NHibernate.Examples.QuickStart.User, NHibernate.Examples" table="user">
    <id name="Id" column="LogonId" type="String" length="20">
    <generator class="assigned" />
    </id>
    <property name="UserName" column="Name" type="String" length="40"/>
    <property name="Password" type="String" length="20"/>
    <property name="EmailAddress" type="String" length="40"/>
    <property name="LastLogon" type="DateTime"/>
    </class>
    </hibernate-mapping>

--- User.hbm.xml end ---


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 13, 2007 4:38 pm 
Beginner
Beginner

Joined: Thu Oct 19, 2006 1:03 pm
Posts: 29
Is that the complete exception that's being thrown? Because if it says mapping exception it often throws more than that...

Hard to help you without the complete exception.


Top
 Profile  
 
 Post subject: thanks for asking
PostPosted: Sat Apr 14, 2007 10:21 am 
Newbie

Joined: Fri Apr 13, 2007 2:50 pm
Posts: 3
Location: Cincinnati Ohio
I found where the IDE allows be to cut and paste the "details". Although I don't see a lot of helpful inf. in the detail; maybe you will.

Would a copy of app.config or something els be helpful?

    NHibernate.MappingException was unhandled
    Message="Could not add assembly NHibernate.Examples"
    Source="NHibernate"
    StackTrace:
    at NHibernate.Cfg.Configuration.LogAndThrow(MappingException me)
    at NHibernate.Cfg.Configuration.AddAssembly(String assemblyName)
    at WindowsApplication1.Program.Main() in C:\test-nHibernate\WindowsApplication1\WindowsApplication1\Program.cs:line 24
    at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
    at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading.ThreadHelper.ThreadStart()


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 14, 2007 10:41 am 
Beginner
Beginner

Joined: Thu Oct 19, 2006 1:03 pm
Posts: 29
Ok, no doesn't seem like the exception details will help you.

What _will_ help you track it down, though is to enable logging.

Code:
   <log4net>
      <!-- Define some output appenders -->
      <appender name="rollingFile" type="log4net.Appender.RollingFileAppender,log4net" >

         <param name="File" value="log.txt" />
         <param name="AppendToFile" value="true" />
         <param name="RollingStyle" value="Date" />
         <param name="DatePattern" value="yyyy.MM.dd" />
         <param name="StaticLogFileName" value="true" />

         <layout type="log4net.Layout.PatternLayout,log4net">
            <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" />
         </layout>
      </appender>
      <appender name="NHibernateFileLog" type="log4net.Appender.RollingFileAppender">
         <file value="logs/nhibernate.txt"/>
         <appendToFile value="true"/>
         <rollingStyle value="Size"/>
         <maxSizeRollBackups value="10"/>
         <maximumFileSize value="200KB"/>
         <staticLogFileName value="true"/>
         <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%d{HH:mm:ss.fff} [%t] %-5p %c -&gt; %m%n"/>
         </layout>
      </appender>

      <!-- Setup the root category, add the appenders and set the default priority -->

      <root>
         <priority value="ALL" />
         <appender-ref ref="rollingFile" />
      </root>
      <logger name="NHibernate" additivity="false">
         <level value="DEBUG"/>
         <appender-ref ref="NHibernateFileLog"/>
      </logger>
   </log4net>

as a child of configuration in app.config.

and
Code:
      <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
as a child of configurationSections, given that you have included the log4net assembly in the application.

If you then look up that file which is created when you run the program, NHibernate will have written debug information to that.

On the other hand, I agree, learning the basics should be easy enough. Try following the tutorial to the point instead, and have a look at codeproject and Billy McCafferty's articles there for a more thorough understanding of what you can do.

(and when you get to version 1.2 of his articles, consider my comment under the name [echo] instead of his own architecture in the enterprise app)


Top
 Profile  
 
 Post subject: thats great help
PostPosted: Sat Apr 14, 2007 11:24 am 
Newbie

Joined: Fri Apr 13, 2007 2:50 pm
Posts: 3
Location: Cincinnati Ohio
I am looking for a paid consultant on this if you or you know an interested party. I need to be brought up to speed for a much larger project than the one I'm representing here.


echoSwe wrote:
Ok, no doesn't seem like the exception details will help you.

What _will_ help you track it down, though is to enable logging.

Code:
   <log4net>
      <!-- Define some output appenders -->
      <appender name="rollingFile" type="log4net.Appender.RollingFileAppender,log4net" >

         <param name="File" value="log.txt" />
         <param name="AppendToFile" value="true" />
         <param name="RollingStyle" value="Date" />
         <param name="DatePattern" value="yyyy.MM.dd" />
         <param name="StaticLogFileName" value="true" />

         <layout type="log4net.Layout.PatternLayout,log4net">
            <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" />
         </layout>
      </appender>
      <appender name="NHibernateFileLog" type="log4net.Appender.RollingFileAppender">
         <file value="logs/nhibernate.txt"/>
         <appendToFile value="true"/>
         <rollingStyle value="Size"/>
         <maxSizeRollBackups value="10"/>
         <maximumFileSize value="200KB"/>
         <staticLogFileName value="true"/>
         <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%d{HH:mm:ss.fff} [%t] %-5p %c -&gt; %m%n"/>
         </layout>
      </appender>

      <!-- Setup the root category, add the appenders and set the default priority -->

      <root>
         <priority value="ALL" />
         <appender-ref ref="rollingFile" />
      </root>
      <logger name="NHibernate" additivity="false">
         <level value="DEBUG"/>
         <appender-ref ref="NHibernateFileLog"/>
      </logger>
   </log4net>

as a child of configuration in app.config.

and
Code:
      <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
as a child of configurationSections, given that you have included the log4net assembly in the application.

If you then look up that file which is created when you run the program, NHibernate will have written debug information to that.

On the other hand, I agree, learning the basics should be easy enough. Try following the tutorial to the point instead, and have a look at codeproject and Billy McCafferty's articles there for a more thorough understanding of what you can do.

(and when you get to version 1.2 of his articles, consider my comment under the name [echo] instead of his own architecture in the enterprise app)


Top
 Profile  
 
 Post subject: Re: thats great help
PostPosted: Sat Apr 14, 2007 12:12 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
stevesl wrote:
I am looking for a paid consultant on this if you or you know an interested party. I need to be brought up to speed for a much larger project than the one I'm representing here.


JBoss provides support and consulting for NHibernate.

About your problem: you should look into inner exceptions of the exception being thrown. Just the stack trace of the outer exception is not enough.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.