C # how to solve the problem that the object reference is not set to the object instance during Interface Design

Source: Internet
Author: User

C # how to solve the problem that the object reference is not set to the object instance during Interface Design
When you are working on a. Net project, you often encounter the problem of not setting the object reference to the object instance during the design interface. The solution is as follows:
1. The Winform and Asp. Net interfaces can be designed as follows:
Winform project:

Protected override void OnLoad (EventArgs e) {base. onLoad (e); if (string. compare (Process. getCurrentProcess (). processName, devenv) = 0) return; // other related code, or // if (string. compare (Process. getCurrentProcess (). processName, devenv )! = 0) // {// other related code, //} // or // if (! This. DesignMode )//{}}


Sometimes some operations must be added to the constructor (although this is not recommended), this problem also occurs, and the write in the constructor is slightly different.
Public BuroHomeFrm () {InitializeComponent (); if (string. Compare (Process. GetCurrentProcess (). ProcessName, devenv )! = 0) {// other code ..... }



Or
// If (! This. DesignMode) // {Other code} // if it is still written in that way, an error is returned. // If (string. Compare (Process. GetCurrentProcess (). ProcessName, devenv) = 0) // return ;}


Asp. Net
2. for WPF, you can refer to the above writing method. There is also another writing method.
If (! DesignerProperties. GetIsInDesignMode (this) {// other code}

 

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.