Tracking code (.NET) in design period

zhaozj2021-02-16  88

Problem in the development: The base class form is defined in the WinForm window. When you open the sub-form in the designer, you will have a window that cannot be used in the designer, which happens ... The information of the abnormality, and the form cannot be opened, and there is no way to use the form designer to interface design. But everything is running.

The reason for this problem is to perform its base class when you double-click the form to open in the Solution Explorer, which is to perform some of the code in the parent form, for example:

Create a base class form, named FormBase, build a subclass form formderive, inherited from FORMBASE PUBLIC CLASSMDERIVE: FORMBASE {private system.componentmodel.container components = NULL;

Public formderive () {initializecomponent ();} .........................

Then add a sentence in the constructor of the base class form: public formBase () {initializationComponent ();

MessageBox.show ("It's base form!");}, Then double-click the Formderive Open Designer in The Solution Explorer, then there is a MessageBox pop-up, then display the design interface of Formderive.

Now let the code in the FORMBASE exception, write a code that generates "array crosions"

String [] array = new string [] {"1", "2", "3"}; for (int i = 0; i <= array.length; i ) {messagebox.show (array [i]); } Open the designer again, pop up the dialog, the designer is blank, prompt:? An exception is attempted to create an instance of WindowsApplication 12.FormBase. An exception is "index beyond the array boundary." • If you insert the code that causes an exception in the FormBase's LOAD event, the same phenomenon occurs when using the designer.

If the code in the base class is relatively simple, you can find a problem with reading, then the code is more complicated? I just said that the topic is now. A debug tool DBGCLR.EXE is provided in .NET, it can track the code 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 on the menu: Tool-debugging process, will list the current system's process. Select the DEVENV.EXE process, that is, the vs.net integrate development environment, point addition. Close the dialog. Open the .cs file you want to debug in DBGCLR, where you choose the formBase.cs file and then add a breakpoint to the FORMBASE constructor. Re-open Formderive, when interrupt in DBGCLR, you can debug.

Summary: I have encountered such a form that does not open, it is important to read some configuration files, that is, there is no specified file under the path specified by the design period, but use the generation after the runtime. Copy came over, so there is no problem in the running period.

This problem has been a half-day, knowing the method of debugging, and then there is no fear.

DBGCLR.EXE uses in the help, I have explained it, I didn't notice it before: .NET FRAMEWORK-> Tools and Debugger -> CLR Debugger

转载请注明原文地址:https://www.9cbs.com/read-14448.html

New Post(0)