.config in control

Hi all,

i've got a .config file wich i use in a application (vb.net 2003)
i'm binding (dynamic properties) the .config file to properties in a control.
When i drag n drop the control on a form i got a error and the instance of the control is removed from the form
The error is something like this

Exception occurred while trying to make a instance of subformacties
"The key sql.connectionstr does not exist in the configuration section"

Tnx in advance

[482 byte] By [RemcoJVG] at [2007-12-16]
# 1
Dynamic properties and user controls never worked quite as well as you'd like. This is one of the reasons that we added the new settings designer/client configuration API in Visual Studio 2005 (including the ability to bind properties to settings).

This is the problem:

When dragging the user control to the windows onto the windows forms designer, the designer will actually create an instance of the control. This will execute all the code in the InitializeComponent method, including the call where the user control tries to get the value from the application's configuration file. The problem is that the application that created the user control is Visual Studio, so the user control will end up looking in devenv.exe.config for the dynamic property, not in the app.config in your project.

So, how do you solve this?

If you are using Visual Studio 2005, I'd recommend moving away from dynamic properties and use the settings designer/client configuration instead.

If you are using Visual Studio 2003, I would suggest that instead of binding the property in the user control, you add a public property on the user control. You can then use dynamic properties in your windows application that you wanted to add your user control to and bind this new property to a value in app.config. This way, the dynamic property should be defined correctly in the app.config file in the windows application, and things should work as expected.

Best regards,
Johan Stenberg

JohanStenberg at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
Johan Stenberg wrote:

The problem is that the application that created the user control is Visual Studio, so the user control will end up looking in devenv.exe.config for the dynamic property, not in the app.config in your project.
rg

As a matter of fact, i tried to put the dyn. properties in the devenv.exe.config file.
but this did not worked

RemcoJVG at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
Johan Stenberg wrote:

If you are using Visual Studio 2003, I would suggest that instead of binding the property in the user control, you add a public property on the user control. You can then use dynamic properties in your windows application that you wanted to add your user control to and bind this new property to a value in app.config. This way, the dynamic property should be defined correctly in the app.config file in the windows application, and things should work as expected.

Best regards,
Johan Stenberg

As i understand it. I will lose some designtime futures Such as databinding in the usercontrol

RemcoJVG at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic General...