Bug Report T816679
Visible to All Users

Code Cleanup – The "Make properties auto-implemented" code cleanup incorrectly works with WinForms Designer Files

created 5 years ago

I have the following options set:
- "Editor" => "C#" => "Code Cleanup" => "Apply Code Cleanup when saving a document"
- "Editor" => "C#" => "Code Cleanup" => "Make properties auto-implemented"
To reproduce the problem:

  1. Create a XtraForm, add a control (doesn't matter which) and save it .
    Then, you'll have something like this as designer file:
C#
namespace Testing.Forms { partial class XtraForm1 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.labelControl1 = new DevExpress.XtraEditors.LabelControl(); this.SuspendLayout(); // // labelControl1 // this.labelControl1.Location = new System.Drawing.Point(85, 68); this.labelControl1.Name = "labelControl1"; this.labelControl1.Size = new System.Drawing.Size(63, 13); this.labelControl1.TabIndex = 0; this.labelControl1.Text = "labelControl1"; // // XtraForm1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(290, 268); this.Controls.Add(this.labelControl1); this.Name = "XtraForm1"; this.Text = "XtraForm1"; this.ResumeLayout(false); this.PerformLayout(); } #endregion private DevExpress.XtraEditors.LabelControl labelControl1; } }
  1. Go to the code-behind file and define a property, which returns the added control:
C#
public LabelControl Label => labelControl1;
  1. Save this code-behind file and the code cleanup will produce a little mess.
    That's, what I get after the save.:
    Code-behind file:
C#
public LabelControl Label { get ; private set; }

Designer file:

C#
namespace Testing.Forms { partial class XtraForm1 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { Label = new DevExpress.XtraEditors.LabelControl(); this.SuspendLayout(); // // labelControl1 // Label.Location = new System.Drawing.Point(85, 68); Label.Name = "labelControl1"; Label.Size = new System.Drawing.Size(63, 13); Label.TabIndex = 0; Label.Text = "labelControl1"; // // XtraForm1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(290, 268); this.Controls.Add(Label); this.Name = "XtraForm1"; this.Text = "XtraForm1"; this.ResumeLayout(false); this.PerformLayout(); } #endregion } }

So, the designer file is corrupted and I can't use the designer anymore.

In my opinion, the designer file should never be changed during a code cleanup.

Comments (1)
DevExpress Support Team 5 years ago

    Hi,
     
    Thank you for pointing out this issue and providing code samples.
     
    I have reproduced this behavior when a designer file is corrupted after applying the "Make properties auto-implemented" Code-Cleanup rule.

    In my opinion, the designer file should never be changed during a code cleanup.

    CodeRush has check on designer-files and doesn't apply the Code Cleanup feature on these files. In your case, Code Cleanup is applied not on a designer-file (on a code-behind file) but the "Make properties auto-implemented" rule also modifies a designer-file. We agree that this behavior is wrong. We will correct code cleanup rules that to not modify designer files in these cases. As soon as we correct it, we will notify you.

    Answers approved by DevExpress Support

    created 5 years ago

    We have fixed the issue described in this ticket and will include the fix in our next maintenance update. To apply this solution before the official update, request a hotfix by clicking the corresponding link for product versions you require.

    Note: Hotfixes may be unavailable for beta versions and updates that are about to be released.

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.