can't drag usercontrol to a form

T

Tarscher

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());
}
}
 
C

ClayB

Has ConfigurationManager.ConnectionStrings been created and populated
at this point in your code? Does it contain the "connectionString"
value?

===================
Clay Burch
Syncfusion, Inc.
 
T

Tarscher

Has ConfigurationManager.ConnectionStrings been created and populated
at this point in your code? Does it contain the "connectionString"
value?

===================
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top