The design encountered such problems in development:
The base class form is defined in the WinForm window, and when the subclass form is opened in the designer
Something like "a window cannot be designed with a designer," occurs ... Exception, and the form cannot be opened, there is no way to design the interface using the form designer. But everything works fine.
The reason for this is that when you double-click a form to open the design in Solution Explorer, you execute its base class, which is some code in the parent form, for example:
Create a base class form named Formbase, then create a subclass form Formderive, inherit from Formbase
public class Formderive:formbase
{
Private System.ComponentModel.Container components = null;
Then add the sentence code to the constructor of the base class form:
Public Formbase ()
{
InitializeComponent ();
MessageBox.Show ("It ' s Base form!");
}
Compile, and then double-click Formderive in Solution Explorer to open the designer, a MessageBox pops up and then the Formderive design interface is displayed.
Now to get the code in Formbase to be an exception, write a simplest code that produces "array out of Bounds"
string[] array = new string[]{"1", "2", "3"};
for (int i = 0; I <= array. Length; i++)
{
MessageBox.Show (Array[i]);
}
Open the designer again, after the pop-up dialog box, the designer is blank, prompting:
An exception occurred while trying to create an instance of Windowsapplication12.formbase. Exception is "index exceeded array bounds." ”
?
If you insert the code that caused the exception in the Formbase load event, the same behavior occurs when you use the designer.
If the code in the base class is simpler and can be read to find the problem, is the code more complex?
It's time to talk.
A debugging tool, DbgClr.exe, is provided in. NET, which allows code tracking in the designer.
If you can't find this file, you can use the search file to find it.
Here's how to use DBGCLR tracking:
Run DbgClr.exe
Click menu: Tools-Debug process, will list the current system process.
Select the devenv.exe process, that is, the Vs.net integrated development environment, point attach. Closes the dialog box.
In DbgClr, open the. cs file you want to debug, where you select the FormBase.cs file
It then adds a breakpoint to the Formbase constructor where the for loop is made.
Reopen the formderive, which is interrupted in the dbgclr and can be debugged.
Summary: I came across a situation where this form is not open. It is important to read some configuration files, that is, there is no file specified under the path specified in the design period, but the file is copied with the Post-build event at run time, so the runtime is fine.
This question has done me for a while, knew the debugging method, again appears this question not to be afraid of.
The use of DbgClr.exe is explained in Help, how I didn't notice it before:
. NET framework-> Tools and Debugger->CLR debugger
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.