473,405 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Any way to tell if you are in the designer from a static function?

We have a control that is throwing an exception in a static initializer
when viewed in VS2005 designer as a subcontrol on a form. The exception
doesn't get thrown when designing the control itself, nor does it get
thrown in normal run-time, so it must have something to do with the fact
that the control is being loaded in the designer.

I know there is a 'this.DesignMode' available, but I can't use it from the
static contructor (since I don't have access to 'this'). I don't want to
simply catch and throw away the exception. Is there some other way that I
can determine if I'm in the designer?

-mdb

Dec 27 '07 #1
7 1247

"Michael Bray" <mb*****************@you.figure.it.out.comwrote in message
news:Xn****************************@207.46.248.16. ..
We have a control that is throwing an exception in a static initializer
when viewed in VS2005 designer as a subcontrol on a form. The exception
doesn't get thrown when designing the control itself, nor does it get
thrown in normal run-time, so it must have something to do with the fact
that the control is being loaded in the designer.

I know there is a 'this.DesignMode' available, but I can't use it from the
static contructor (since I don't have access to 'this'). I don't want to
simply catch and throw away the exception. Is there some other way that I
can determine if I'm in the designer?
Fix the error instead of bypassing/working around it. You will have to load
Visual Studio itself in the debugger, to do that set the debug executable
for the control library to the visual studio exe and then debug with that
startup project. Visual Studio will start, and when you open the designer
and cause the exception, you'll get to debug through your type initializer
and see exactly what goes wrong.
>
-mdb

Dec 27 '07 #2
"Ben Voigt [C++ MVP]" <rb*@nospam.nospamwrote in
news:u5**************@TK2MSFTNGP03.phx.gbl:
Fix the error instead of bypassing/working around it. You will have
to load Visual Studio itself in the debugger, to do that set the debug
executable for the control library to the visual studio exe and then
debug with that startup project. Visual Studio will start, and when
you open the designer and cause the exception, you'll get to debug
through your type initializer and see exactly what goes wrong.
I know exactly where the problem is, because the designer actually tells me
the exact file and line number that caused the control to not be able to
load (and thus I can't view the hosting control.)

But the real problem is that it is with an instance call to
Assembly.GetTypes(), so the exception is being thrown from the .NET
Framework itself... Obviously I can't fix that... so am I back to trying
to determine if I'm in design mode, or can you suggest anything else?

-mdb
Dec 27 '07 #3
Michael Bray wrote:
We have a control that is throwing an exception in a static initializer
when viewed in VS2005 designer as a subcontrol on a form. The exception
doesn't get thrown when designing the control itself, nor does it get
thrown in normal run-time, so it must have something to do with the fact
that the control is being loaded in the designer.

I know there is a 'this.DesignMode' available, but I can't use it from the
static contructor (since I don't have access to 'this'). I don't want to
simply catch and throw away the exception. Is there some other way that I
can determine if I'm in the designer?
Look into LicenseManager.UsageMode
Chris.
Dec 27 '07 #4
Chris Shepherd <ch**@nospam.chsh.cawrote in
news:#L**************@TK2MSFTNGP03.phx.gbl:
Look into LicenseManager.UsageMode
Ahhh sweet bliss. That works perfectly! Thanks much!

-mdb
Dec 27 '07 #5
Michael Bray wrote:
Chris Shepherd <ch**@nospam.chsh.cawrote in
news:#L**************@TK2MSFTNGP03.phx.gbl:
>Look into LicenseManager.UsageMode

Ahhh sweet bliss. That works perfectly! Thanks much!
You are very welcome.

Chris.
Dec 27 '07 #6

"Michael Bray" <mb*****************@you.figure.it.out.comwrote in message
news:Xn****************************@207.46.248.16. ..
"Ben Voigt [C++ MVP]" <rb*@nospam.nospamwrote in
news:u5**************@TK2MSFTNGP03.phx.gbl:
>Fix the error instead of bypassing/working around it. You will have
to load Visual Studio itself in the debugger, to do that set the debug
executable for the control library to the visual studio exe and then
debug with that startup project. Visual Studio will start, and when
you open the designer and cause the exception, you'll get to debug
through your type initializer and see exactly what goes wrong.

I know exactly where the problem is, because the designer actually tells
me
the exact file and line number that caused the control to not be able to
load (and thus I can't view the hosting control.)
The information shown by the designer is worthless. I'd guess you're seeing
the TypeLoadException caught by the designer. It's the InnerException
property that contains the useful information. Run the design environment
in the debugger.
But the real problem is that it is with an instance call to
Assembly.GetTypes(), so the exception is being thrown from the .NET
Framework itself... Obviously I can't fix that... so am I back to trying
to determine if I'm in design mode, or can you suggest anything else?
No, the framework is catching an exception thrown inside your code and
wrapping it in a TypeLoadException.
>
-mdb

Dec 27 '07 #7
"Ben Voigt [C++ MVP]" <rb*@nospam.nospamwrote in
news:e9**************@TK2MSFTNGP04.phx.gbl:
The information shown by the designer is worthless. I'd guess you're
seeing the TypeLoadException caught by the designer. It's the
InnerException property that contains the useful information. Run the
design environment in the debugger.
I wouldn't say it is worthless - it told me where the problem was... But
here's a strange twist - I can't get it to fail now. I was finally able to
at least get it to load in the designer by inserting a call to
System.Diagnostics.Debugger.Break() in the static method, but there is no
sign of the error that was causing the original issue, despite the fact
that the code hasn't changed. Unfortunately, neither was I able to notice
any factor which would have caused the original problem even as I debugged
the environment. And, once I was done debugging, my original VS process
was unresponsive and I had to kill it.

Interesting process, though.

-mdb
Dec 28 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: | last post by:
Hi, We have a form designed in the VS designer in C# and everytime we build on different machiens its chainging the .Location and .Size properties yet we are not changing anything in this. We...
31
by: DeltaOne | last post by:
#include<stdio.h> typedef struct test{ int i; int j; }test; main(){ test var; var.i=10; var.j=20;
0
by: Steve Rosenberry | last post by:
I have a class that inherits from System.Windows.Forms.Label. The background image for my class is drawn using a bitmap as a template. Every instance should use the same bitmap (so I'm thinking...
4
by: Sebastian Bargmann | last post by:
Hi, I've run into a weird problem with the form designer. I have three classes: a messagebox class and two forms (Base and Derived which is derived from Base): (note: only relevant code...
5
by: Franco, Gustavo | last post by:
Hi, I have a question, and please I need a answer. How can I finalize a thread running with Application.Run (I need the message loop!!!) without call Thread.Abort?. I want to call...
0
by: Ken Dopierala Jr. | last post by:
Hi, When I change properties through the property window on my custom control and then move focus from that property cell VS.Net runs the GetDesignTimeHtml() method on my designer. When I...
0
by: Mike | last post by:
Hi All, I am using a COM object and so I have to use a form for it to work. The problem is I need to run it as a service as well. When I run it in a test scenario everything works fine and...
2
by: Charlie | last post by:
Hi: Program runs and compiles fine, but WinForms designer breaks when using this line of code... ConfigurationManager.ConnectionStrings.ToString(); It says "Object reference not set to an...
0
by: Mahmoud Al-Qudsi | last post by:
Hi all, What is the recommended way of binding controls to a *static* datasource? In my project, I have to use the same ADO.net data source/ bindingsource in mulitple forms and across...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.