-->
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.  [ 4 posts ] 
Author Message
 Post subject: Visual Studio trying to instantiate NHibernate in designer
PostPosted: Thu May 15, 2008 7:23 pm 
Newbie

Joined: Thu May 15, 2008 6:43 pm
Posts: 3
NHibernate version: 1.2.1GA

I have created a user control that references a binary created in another project. That binary uses NHibernate for its data access methods.

Development on this control has been fine until I restarted Visual Studio. Now, opening the main form brings up an error message that it has thrown an exception in design mode. The exception at had is displayed on the form in Visual studio, and is the standard exception thrown when NHibernate cannot find the XML file describing the database settings.

That is, "System,TypeInitializationException: The type initializer for 'Remoting.Factory.NHibernateFactory' threw an exception. ---> NHibernate.HibernateException: problem parsing configuration : System.IO.FileNotFoundException: Could not find file 'C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\SQLServer.cfg.xml' ..."

and on and on.

Any help on how I can keep visual studio from trying to create an NHibernate instance while I'm not running/debugging?

The offending code (in the user control)
Code:
        private void userPanel_VisibleChanged(object sender, EventArgs e)
        {
            try
            {
                if (((UserControl)sender).Visible == true)
                {//If visible, get and bind for both creating and editing
                    _cData = new DataSource();
                    _companyList = _cData.GetCompanyList(_thisAppGuid);

                    foreach (Company index in _companyList)
                    {
                        uxUserCompanyIDCombobox.Items.Add(index.CompanyNumber);
                        uxUserCompanyReportComboBox.Items.Add(index.CompanyNumber);
                        uxEditCompanyComboBox.Items.Add(index.CompanyNumber);
                    }
                }
                else
                {//else, clear variables and UI components.
                    _cData = null;
                    if (_companyList != null)
                        _companyList.Clear();
                    uxUserCompanyIDCombobox.Items.Clear();
                    uxUserCompanyReportComboBox.Items.Clear();
                    uxEditCompanyComboBox.Items.Clear();
                }
            }
            catch (Exception)
            {
               
                throw;
            }
        }


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 16, 2008 2:40 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Sourround the code with

if ( !DesignMode )
{
...
}

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 16, 2008 12:34 pm 
Newbie

Joined: Thu May 15, 2008 6:43 pm
Posts: 3
That seems to have taken care of it. Thank you very much.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 16, 2008 12:41 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
I ran into problems using this approach with UserControls on inherited forms. Visual Studio doesn't get the DesignMode right there - seems to be a known bug :-(. But if you just use your control in normal forms, it should work.

_________________
--Wolfgang


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