By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,963 Members | 1,778 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,963 IT Pros & Developers. It's quick & easy.

Descendant form will not display in design mode

P: n/a
I have a winform base class in which I dynamically set a web reference Url:

myService.Url = <WebServer> + "MyService.asmx";

where <WebServer> is pulled from my App.config file.

There is no problem working with this base class and the solution compiles
and runs fine. However, I am unable to display any descendant forms in
design mode in VS.NET 2003. I get a message indicating that:

"An exception occurred while trying to create and instance of <form base
class>. The exception was "Invalid URI: The format of th URI could not be
determined."

Clearly, it cannot resolve the dynamic web reference in the base class. The
immediate work-around is to:

1. comment out the assignment and rebuild
2. do any descendant form design
3. uncomment the assignment and rebuild

Surely, there is a mode elegant mechanism to address this issue?

Thanks,
Chris.
Nov 16 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
if (!this.DesignMode)
{
myService.Url = <WebServer> + "MyService.asmx";
}

I've found that in many cases I've had to put this at the beginning of
forms methods so that they don't bother running in design mode:

if (this.DesignMode)
{
return;
}

Nov 16 '05 #2

P: n/a
Yes, 'this.DesignMode' was my first thought but, alas, does not work. That
would be too easy. ;-)

Thanks,
Chris.
Nov 16 '05 #3

P: n/a
Can you post more code surrounding your problem?

Every problem I've had with the designer refusing to display a child
form has been because some method is running and trying to do "run
time" stuff in a design environment, and this.DesignMode is the
solution.

However, figuring out exactly which method it is and what it's trying
to do can be a bear. To this day I have two forms that _sometimes_ fail
to display in design mode with a message that there is a null
reference. Do you think I can figure out which method is being run
(which shouldn't be)? Naaah....

It's likely that it's not failing on the line of code you think it is:
that it's failing somewhere else.

Nov 16 '05 #4

P: n/a
"Bruce Wood" <br*******@canada.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Can you post more code surrounding your problem?

There is nothing else in the base form constructor other that the
InitializeComponent() call and the instantiation of the myService class
prior to setting the URL.
Every problem I've had with the designer refusing to display a child
form has been because some method is running and trying to do "run
time" stuff in a design environment, and this.DesignMode is the
solution.

However, figuring out exactly which method it is and what it's trying
to do can be a bear. To this day I have two forms that _sometimes_ fail
to display in design mode with a message that there is a null
reference. Do you think I can figure out which method is being run
(which shouldn't be)? Naaah....

It's likely that it's not failing on the line of code you think it is:
that it's failing somewhere else.


Well, all I need to do to get the descendant to display is comment out the
one line. Another option is to move the assignment line to the descendant
constructor and no problem. I guess this is just one of those things you
live with.

Thanks again,
Chris.
Nov 16 '05 #5

P: n/a
Ah... that makes sense.

DesignMode isn't set until your form has a window handle. The
constructor is too soon for that, so it returns "false".

The solution is to do as little as possible in the constructor, and do
as much set-up as possible in the form's ..._Load() method, where you
_do_ have a window handle and you _can_ use DesignMode effectively.

Perhaps if you set up Load method for your form (virtual, of course, so
your child classes can override it) and do your initialization in there?

Nov 16 '05 #6

P: n/a

"Bruce Wood" <br*******@canada.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...
Ah... that makes sense.

DesignMode isn't set until your form has a window handle. The
constructor is too soon for that, so it returns "false".


Light bulb!

Thank you sir; all is well using the Load.

Chris.

Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.