Tracking code (. NET) during winform Design)

Source: Internet
Author: User

This problem occurs during development:
The winform window defines the base class form. When opening the subclass form in the designer
The following occurs: "The Window cannot be designed with the designer ...... and the form cannot be opened. Therefore, the Form Designer cannot be used to design the interface. But everything works normally.

The cause of this problem is that when you double-click the form in Solution Explorer to open the form for design, it will execute its base class, that is, someCodeFor example, create a base class form named formbase, and then create a subclass form formderive, inherited from formbase
Public class formderive: formbase
{
Private system. componentmodel. Container components = NULL;
Public formderive ()
{
Initializecomponent ();
}
...........................
}

Then, add the following code to the constructor of the base-class form:
Public formbase ()
{
Initializecomponent ();
MessageBox. Show ("It's base form! ");
}

Compile and double-click formderive in Solution Explorer to open the designer. A MessageBox pops up and the formderive design interface is displayed.

Now let's let the code in formbase get abnormal, write the simplest code that generates "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. In the dialog box that appears, the designer is blank. The prompt is: an exception occurred when trying to create a windowsapplication12.formbase instance. Exception: "The index exceeds the array limit ."
 
If you insert code that causes exceptions in the load event of formbase, the same occurs when you use the designer.

If the code in the base class is relatively simple, you can find the problem by reading it. What is the complexity of the code?

Dbgclr.exe, a tool used in .net, can trace code in the designer.
If you cannot find this file, you can use "search file" to find it.

The following describes how to use dbgclr tracking:
Run dbgclr.exe
Click "tool-debug process" to list the processes of the current system.

Select the devenv.exe process, that is, the integrated development environment of vs.net. Click attach. Close the dialog box.
Open the. CS file to be debugged in dbgclr. Select the formbase. CS file here.

Add a breakpoint to the place where the formbase constructor performs the for loop.
Re-open formderive, which will be interrupted in dbgclr and can be debugged.

Summary: when I encounter a situation where the form cannot be opened, it is generated when I read some configuration files, that is, the files not specified in the path specified during the design period, however, during runtime, the generated event is used to copy the file, so there is no problem during runtime.

I 've been suffering this problem for a long time. I know the debugging method, and I am not afraid of it again.

the use of dbgclr.exe is explained in the help section. Why didn't I notice it before?
. NET Framework-> Tools and debugger-> CLR debugger

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.