Topaz Filer: if you use e-mail for business, we can save you money and decrease your risk.
Designer is having a hard time with dynamic properties
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.windowsforms.designtime.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Uri Dor
Hi, everyone,

While trying to be a nice guy and putting my connection string in a
dynamic property, VS.NET 2003 decided to test my limits...
So I created a minimal test case for your enjoyment.

Attached are 2 source files with the code. Basically all I did was add a
usercontrol UserControl1, which has a TextBox with its Text property
coming from the app.config file.

When I open UC1 in the Designer all is fine, I see the text and all is
well. Oh Joy.
But when I open the form and try to add a UC1 to it, I get:

---------------------------
Microsoft Development Environment
---------------------------
An exception occurred while trying to create an instance of
DynamicProperties.UserControl1. The exception was "The key 'KukuText'
does not exist in the appSettings configuration section.".
---------------------------
OK
---------------------------

Does anybody have an idea why this happens?

Of course the problem gets worse on my real project, where Form1 and UC1
already existed before I made the property dynamic, in which case the
designer destroys a chunk of my code each time the form is opened.

Thanx in advanx
Uri

Reply to this message...
Vote that this is a GOOD answer...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
Jeffrey Tan[MSFT] (VIP)
Hi Uri,

Sorry for letting you wait for so long time.

I have reproduced out your problem. After doing some research, I found that
this is a known issue of our product.

This problem only occurs at design-time, so to workaround this issue, we
may disable the design-time code snippet, like this:
//usercontrol's OnLoad method
protected override void OnLoad(EventArgs e)
{
    if(this.DesignMode==false)
    {
        System.Configuration.AppSettingsReader configurationAppSettings = new
System.Configuration.AppSettingsReader();
        this.textBox1.Text =
((string)(configurationAppSettings.GetValue("KukuText", typeof(string))));
    }
    base.OnLoad (e);
}

===============================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Uri Dor
Thanks, Jeffrey, but I *need* the property at design-time - it's a
connection string which I want to use to design queries, generate
datasets, etc.

Jeffrey Tan[MSFT] wrote:

[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Jeffrey Tan[MSFT] (VIP)
Hi Uri,

Thanks very much for your feedback.

Just as the name of Dynamic property suggested, it is usually used to
retrieve property values dynamically at run time. If you really want to
retrieve the property value from app.config at design-time, I think Andy's
suggestion may be a workaround, just treat app.config as a normal xml file
and retrieve its value through some xml classes. The below article may help
you:
http://www.codeproject.com/csharp/ConfigSectionHandler.asp

Hope this helps,

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Andy Becker
"Uri Dor" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

I like your approach of getting all this in one (configurable) place.

AppSettingsReader probably isn't going to work quite right from the
designer, the underlying assembly which is loading your stuff is really the
IDE, not your base executable. I think the best approach at this point
would be to use something other than AppSettingsReader to get the values
(from the same file) at design time, checking DesignMode as suggested.

You will probably have to jump through a few hoops to find the config file
relative to the assembly containing your form, etc., and it will probably
rely on a certain project/solution structure to pull it off - unless you are
working all in one solution. It also means reading the .config file (and
parsing) yourself. There is plenty of code kicking around in the Compact
Framework world for accomplishing this.

Best Regards,

Andy

Reply to this message...
Vote that this is a GOOD answer...
 
Outlook interop - stopping user properties appearing on Outlook message print
Seriously, why is “cut and paste” majorly newsworthy???
 
    
Steven Cheng[MSFT] (VIP)
Hi Uri,

Regarding on the issue, I am
finding proper resource to assist you and we will update as soon as posible.
Thanks for your understanding.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security(This posting is provided "AS IS",
with no warranties, and confers no rights.)

Reply to this message...
Vote that this is a GOOD answer...
 
 
 
System.Configuration.AppSettingsReader
System.EventArgs
System.Web.UI.MobileControls.TextBox
System.Web.UI.WebControls.TextBox
System.Windows.Forms.TextBox




Ad
BootFX
Reliable and powerful .NET application framework.
Recession Busting Bespoke Software
Get through the recession by investing in bespoke software to decrease costs and create commercial opportunities.
Other DN247 Network Sites
.NET 247
SQL Server Wins
Old Skool Developer
 
Copyright © AMX Software Ltd 2008-2009. Portions copyright © Matthew Baxter-Reynolds 2001-2009. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - .NET 247 is a member of the DN247 Network - 4.0.30129.1734