 |
|
 |
Get the process ID of the VS instance you want to be the debugEE, before opening a 2nd (or 3rd or 4th...) instance of VS to be the debugER.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I have come across a number of WSODs that were not solved by the solutions shown here.
Even the test to see if you are running in the IDE (looking at the process name) did not solve it.
I finally discovered why that's so.
In my case, code that is jitt'ed in the IDE was referencing types from a DLL that could not be loaded into Visual Studio. So, the solution to the problem was't preventing code from executing in the IDE, the solution was to prevent code from being jitted in the IDE. The IDE will jit all code that is called from a constructor, on a per-method basis.
Hence, if you have a test that checks to see if you are running in the IDE and the tests indicates you are not, and call code like this:
public class MyControlClass : UserControl { public MyControlClass() { if( ! IsVisualStudio() ) { Foo foo = new Foo(); } } }
In the above, the IsVisualStudio() method returns true if you are running in the IDE (by looking at the current process name), and the Foo instance is not created when you are in the IDE.
Even though the the Foo type is not instantiated at design time, the code for the entire method is jitted, and that's what causes the WSOD.
The solution is to put any code that references types which cannot be jitted at design time in a seperate method, and then call that method via reflection. You have to call the method via reflection because if you call it directly from the constructor, it will be jitted as well.
public class MyControlClass : UserControl { public MyControlClass() { if( ! IsVisualStudio() ) { MethodInfo m = this.GetType().GetMethod("runtimeOnly", BindingFlags.Instance|BindingFlags.NonPublic) m.Invoke( this, null ); } }
void runtimeOnly() { Foo foo = new Foo(); } }
HTH
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Thanks for your reply, it's great to know this article is still useful despite the evolution in technology.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi ,
when am trying to open designer view for a form which is inheriting BaseViewForm getting white screen with this message:
One or more errors encountered while loading the designer. The errors are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes.
Could not load file or assembly 'Wrappers.CLI, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. Hide
at MYnamespace.BaseViewForm..ctor()
Observatrions: 1. In C# project I added a reference to Wrappers.CLI.dll( This Project VC++ project Wrapper one which makes contact from C# code to c++ code) Wrappers.CLI version is 1.0.0.1 but when I added reference to this the VS shows the version as 0.0.0.0 (By looking at properties after adding reference) So suspected the variables from Wrappers.CLI.dll which declared in C# form (which is being opened in design view) may cause the error.
2. I created another BaseViewFormNew without having code related to Wrappers.CLI.dll and made to use this Base form instead of earlier BaseViewForm (which contains code related to Wrappers.CLI.dll then this forms gets opened. This approach worked fine. Then once anyof the forms design view is opened am reverting abck to inherit using older BAseViewForm then surprisingly the design view is getting opened . But this works in one machine in other machines this is not working. So what would be the solutions? No idea.
I tried
1. rebuilding, Clean and rebuilding, deleting bin,obj files 2. steps in http://www.codeproject.com/KB/cs/wsod.aspx 3. Deleting cache fiels from Project Assemblies folder
but none was working..
Thanks, Ramki
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,
Am getting the problem while viewing the designer of the windows form (developed in C#)
C# project has references to wrapper classes(to contact with C++ classes).
Error :
One or more errors encountered while loading the designer. The errors are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes.
Could not load file or assembly Wrappers.CLI, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. Hide
at BaseClass..ctor()
The reference had been added through project browse folder only.
I tried using the steps given in the article but could not get the exact line of code where it was giving this exception.
Thanks, Ramki
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Use Debug.Assert either in a catch clause or as a conditional statement The assertion works even in design mode.
try { } catch(Exception err) { Debug.Assert(false,err.Message); }
or
Debug.Assert(text != null,"The text is noll"); Natza Mitzi
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Thanks for this tip, Natza. I tried what the OP suggested but I couldn't work out how to set this bit:
"Set Visual Studio to break on Common Language Runtime exceptions - Thrown and User-handled"
but your suggestion worked a treat and has saved me hours of head-scratching and teeth-gnashing.
SH 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi, thanks for good article!
But, there is littlebite mistake.
The body of DesignMode property looks like this:
protected bool DesignMode { get { bool result = false; ISite site = this.Site; if ( site != null ){ result = site.DesignMode; }
return result; } }
What it mean? The DesignMode property in constructor always returns False!
------
There is next tricky question.
If you have this classes:
MyTextBox // derives from TextBox
MyUserControl // derives from UserControl and contains one or more controls "MyTextBox"
MainForm // derives from Form and contains one or more controls "MyUserControl"
The Visual Studio Designer sets the Site property only to controls added in designed control/form, but not to controls inside. So, if you open the designer for MainForm the instances of MyUserControls will have the DesignMode set to True bud the instances of MyTextBox will have the DesignMode always set to False.
The solution is the helper class with simple method IsInDesignMode which looks like this:
public static class MyHelperClass { public static bool IsInDesignMode( Control control ) { if ( control == null ) { throw new ArgumentNullException( "control" );
bool result = false; Control ctl = control; do { ISite site = ctl.Site; if ( site != null ) { result = site.DesignMode; if ( result ) { break; } } } while ( ( ctl = ctl.Parent ) != null ); return result; } }
Then the using in the custom/user control should looks like this:
public class MyTextBox : TextBox { public MyTextBox() { ... }
protected override void OnLoad( EventArgs e ) { base.OnLoad( e );
if ( MyHelperClass.IsInDesignMode( this ) == false ) { } } }
/* Geniality is in simplicity. */
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
 |
It's worth mentioning that this behaviour is a 'feature' of VS2005, VS2003 didn't do it, and when reported as a bug, MS reported this was a new feature. I actually have forms that give the WSOD, and don't throw an exception when attaching a second instance, so it can go a little deeper, but your article will help a lot of people who are stuck on this Microsoft insanity.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Christian, I have in fact a form giving WSOD and not throwing exception when attaching a second instance. This is a VB project imported from VS 2003. What can I do? Thanks
Leonardo Presciuttini
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
First step is to look at your load event and start commenting things out, until you find the line that causes the problem. The DesignMode property can be used to make the designer skip lines.
I've posted on the MS forums about my problem and no-one from MS replied, so I was unable to solve my problem, I just live with it.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
In effect my routine at load event contains references to objects which are initialized outside of it. But putting 'exit sub' at the beginning has given no result: all runs as before. Moreover, other forms of mine, which have no load event routine give the same error. But in their case it is sufficient to display the associated resource file (after showing all project files) for the error to disappear. This is not sufficient for the form with load event. ANy
Leonardo Presciuttini
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
Hello,
I'm getting the same errors but for a different reson. I have a class that inherit an activex. now i made that class as a singleton because i want everybody to have an access to it. it is working fine but in design time i can't see the page were the control is in it. (I get an error) my initialization in the designer is like that:
myactivex = ClsActivex.Instance();
In the instance i make the new ClsActivex.
any idea whan can i do to avoid the error?! (i don't care that i wouldn't see the control in design time.
Regarts, Lin.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
 |
I have a sub-class of UserControl that populates a TreeView from a database. This is done in the constructor. I use
if (this.DesignMode) return;
to avoid reading from the database in design mode since the connection information is not available at this time. This works fine when designing the UserControl.
However, when I add the UserControl to a Form I get the "WSOD". It seems that InDesignMode is only set to true when the UserControl itself is opened in the designer.
What I tried is to wrap the code that reads from the database in a try-catch block and ignore any Exception thrown. I do not understand why the Exception that is thrown within the try-block is not caught. Does anyone have a suggestion how to handle this.
Daniel
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
See my comments below.
If your control that is being designed was created with "Add Inherited User Control", you can rely on DesignMode from the class that you are deriving from.
The simple solution for me was to just look at the name of the current process, and see if it was 'devenv'.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
I usually just do:
public SevenHolder() { InitializeComponent(); if ( DesignMode ) return;
}
-- modified at 2:28 Tuesday 28th March, 2006
|
| Sign In·View Thread·PermaLink | 5.00/5 (2 votes) |
|
|
|
 |
|
 |
Of course. That's my "second approach".
My personal coding style (that probably came from coding C/C++ for a long time), is that each and every possible point of failure should be checked. Perhaps somebody has a bug in the singleton? After all it could be someone else's code.
Nadav
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
nadav,
This should be your first approach. Else, you assume that your singleton is there, is initialized, is configured and is ready for the work you want to do with it while in design mode. If that singleton is not behaving, is NOT your designer that should pick that up. To get your form running in the designer, your only concern in your constructor should be only take care that the designer works, and not that some other dependent object is valid.
Tutu.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |