-->
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.  [ 5 posts ] 
Author Message
 Post subject: NHibernate Configuration Problem Visual Studio 2005 Designer
PostPosted: Mon Oct 15, 2007 11:09 am 
Newbie

Joined: Sun Sep 02, 2007 2:37 pm
Posts: 3
I am in the process of using NHibernate as the data access layer for a .NET 2.0 Windows Forms Application. I am encountering a problem related to the way that the Visual Studio Designer renders the form.

I currently have a few user controls that are binding to a collection of objects that are being retrieved using NHibernate. I am storing my NHibernate configuration in the Presentation Layer's App.config, and when I run the application it works perfectly. However, whenever I try to use the Designer, it throws the following error:

'System.IO.FileNotFoundException: Could not find file 'C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\hibernate.cfg.xml''

at NHibernate.Cfg.Configuration.Configure(XmlTextReader reader)
at NHibernate.Cfg.Configuration.Configure(String fileName)
at NHibernate.Cfg.Configuration.Configure()
at KiZAN.Data.NHibernateDataLayer.NHibernateSessionManager.InitSessionFactory() in C:\Documents and Settings\brandonk\My Documents\Visual Studio 2005\Projects\Dismas\CMO\ProjectBase.Data\NHibernateSessionManager.cs:line 59
at KiZAN.Data.NHibernateDataLayer.NHibernateSessionManager..ctor() in C:\Documents and Settings\brandonk\My Documents\Visual Studio 2005\Projects\Dismas\CMO\ProjectBase.Data\NHibernateSessionManager.cs:line 40
at KiZAN.Data.NHibernateDataLayer.NHibernateSessionManager.Nested..cctor() in C:\Documents and Settings\brandonk\My Documents\Visual Studio 2005\Projects\Dismas\CMO\ProjectBase.Data\NHibernateSessionManager.cs:line 49


When the Designer tries to render the form, it's calling cfg.Configure() which is unable to find the configuration file. I have been unable to find anyone else who is having the same problem, and all of the solutions that I find myself are hacks or temporary workarounds.

Thanks in advance for any help that you all might provide.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 15, 2007 12:12 pm 
Senior
Senior

Joined: Thu Feb 09, 2006 1:30 pm
Posts: 172
I think the question to ask is where did you put the configure call in your code? If you were trying to run the NHibernate configuration every time a form is loaded, this is a horrible approach. You should configure NHibernate when the application first loads, and when the application first loads only. There should be no need to continually re-configure it.

Is this what is causing your issue?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 15, 2007 12:16 pm 
Newbie

Joined: Sun Sep 02, 2007 2:37 pm
Posts: 3
I currently have a NHibernateSessionManager Singleton that lazy loads the session when it is first called. The NHibernateSessionManager is in the Data Access layer, and it makes the cfg.Configure() call. However, this call uses the appplication configuration file that is in the entry point assembly. This works with my presentation layer and tests project because I have the configuration information specified in those project's configuration files. However, whenever the designer is the entry point assembly, the configuration file cannot be found.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 16, 2007 12:52 am 
Regular
Regular

Joined: Tue Feb 21, 2006 9:50 am
Posts: 107
Hello,

it seems that you try to load data via NHibernate in the constructor or a method called there. The WindowsForms Designer works in the context of Visuall Studio. He processes the constructor code to render the form. You should avoid to execute code, which depends on configuration files in your application context, in this method. The reason for this is, that the configuration file is read relative to the current application path. For the designer this is the path where the executables of Visual Studio resides. If you run your application, the application path is the bin path of your solution structure. I had this problem also in a non NHibernate application which uses custom configuration files.

To avoid this problem you can try to use the DesignMode property of the form to check, if the form was created by the designer.

Regards
Klaus


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 16, 2007 8:32 am 
Newbie

Joined: Sun Sep 02, 2007 2:37 pm
Posts: 3
Thank you Klaus. The DesignMode property of the form is exactly what I was looking for.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.