Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2007

Tip: Looking for answers? Try searching our database.

can't drag usercontrol to a form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tarscher - 20 Feb 2007 10:25 GMT
Hi all,

I have a usercontrol that doesn't contain a control. When I try to
drop the control on a form I get an error:
Failed to create component'TestcaseUserControl'. The error message
follows: 'System.NullReferenceException: Object reference not set to
an instance of an object.' at Line 20

Line 20 is: TestService m_service = new
TestService(ConfigurationManager.ConnectionStrings["connectionString"].ToString());

I also get compile warning:
- Exception has been thrown by the target of an invocation.

When I remove TestService m_service = new
TestService(ConfigurationManager.ConnectionStrings["connectionString"].ToString());
from the class it works.

Someone knows what's wrong?

Thanks
Stijn

public partial class TestCaseUserControl : UserControl
{
    public TestCaseUserControl()
    {
        InitializeComponent();
        TestService m_service = new
TestService(ConfigurationManager.ConnectionStrings["connectionString"].ToString());
    }
}
ClayB - 20 Feb 2007 11:27 GMT
Has ConfigurationManager.ConnectionStrings been created and populated
at this point in your code? Does it contain the "connectionString"
value?

===================
Clay Burch
Syncfusion, Inc.
Tarscher - 20 Feb 2007 12:19 GMT
> Has ConfigurationManager.ConnectionStrings been created and populated
> at this point in your code? Does it contain the "connectionString"
[quoted text clipped - 3 lines]
> Clay Burch
> Syncfusion, Inc.

I'm not sure whether the ConfigurationManager.ConnectionStrings is
already created and populated (I don't know how to check it) but I
replaced the line with a static string containing the connection
string and the it works perfect. I assume the problem is caused by the
program fetching the connectionstring.

Does this mean I can't use the app.confog to get the connection
string?

Thanks
Stijn

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.