Search code examples
c#winformstoolstripbutton

C# project build errors after importing button image on toolstrip button


I am just starting to use the ToolStrip object on my windows Form.

I followed a nice tutorial that explained how to add the tool strip, then add a button, then assign a image to the button.

So, I added the toolstrip and then added the button:

Add button to toolstrip

As you can see, in the above screen shot I have also tried importing the image. I did this by right-clicking the button and choosing Set Image:

Import button

When I clicked OK, these extra files (MyGenioViewer1.Designer.cs) were automatically generated:

Extra files created

But now the project will not compile. If I restore my previous backup and do everything except importing a button, it compiles.

These are the errors:

Severity    Code    Description Project File    Line    Suppression State
Error   CS0111  Type 'MyGenioView' already defines a member called '.ctor' with the same parameter types    GENIO Viewer    D:\My Programs\GENIO Viewer\GENIO Viewer\MyGenioView.cs 65  Active
Error   CS0262  Partial declarations of 'MyGenioView' have conflicting accessibility modifiers  GENIO Viewer    D:\My Programs\GENIO Viewer\GENIO Viewer\MyGenioView.Designer.cs    25  Active
Error   CS0260  Missing partial modifier on declaration of type 'MyGenioView'; another partial declaration of this type exists  GENIO Viewer    D:\My Programs\GENIO Viewer\GENIO Viewer\MyGenioView1.Designer.cs   25  Active
Error   CS0111  Type 'MyGenioView' already defines a member called '.ctor' with the same parameter types    GENIO Viewer    D:\My Programs\GENIO Viewer\GENIO Viewer\MyGenioView1.Designer.cs   32  Active
Error   CS0121  The call is ambiguous between the following methods or properties: 'MyGenioView.MyGenioView()' and 'MyGenioView.MyGenioView()'  GENIO Viewer    D:\My Programs\GENIO Viewer\GENIO Viewer\GENIO_Viewer_Form.cs   53  Active

Clearly, the addition of these extra files has caused me a problem. I don't know why they were added. I don't know how to resolve the issue. And I don't know how to prevent it.

Thank you for any clarification about resolving this issue correctly.

The original MyGenioView.Designer.cs contains:

namespace GENIO_Viewer
{
  partial class MyGenioView
  {
    /// <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 Component 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.SuspendLayout();
      // 
      // MyGenioView
      // 
      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
      this.Name = "MyGenioView";
      this.ResumeLayout(false);

    }

    #endregion
  }
}

The new MyGenioView1.Designer.cs causing issues is:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace GENIO_Viewer {
    using System;


    /// <summary>
    ///   A strongly-typed resource class, for looking up localized strings, etc.
    /// </summary>
    // This class was auto-generated by the StronglyTypedResourceBuilder
    // class via a tool like ResGen or Visual Studio.
    // To add or remove a member, edit your .ResX file then rerun ResGen
    // with the /str option, or rebuild your VS project.
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    internal class MyGenioView {

        private static global::System.Resources.ResourceManager resourceMan;

        private static global::System.Globalization.CultureInfo resourceCulture;

        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        internal MyGenioView() {
        }

        /// <summary>
        ///   Returns the cached ResourceManager instance used by this class.
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Resources.ResourceManager ResourceManager {
            get {
                if (object.ReferenceEquals(resourceMan, null)) {
                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("GENIO_Viewer.MyGenioView", typeof(MyGenioView).Assembly);
                    resourceMan = temp;
                }
                return resourceMan;
            }
        }

        /// <summary>
        ///   Overrides the current thread's CurrentUICulture property for all
        ///   resource lookups using this strongly typed resource class.
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Globalization.CultureInfo Culture {
            get {
                return resourceCulture;
            }
            set {
                resourceCulture = value;
            }
        }
    }
}

Solution

  • You've got a real mess here. Somehow, you wound up with a Designer file separate from a Form. One that, in fact, doesn't look like a designer file at all. What I didn't see in your screenshot was the form to which those Designers are supposed to be linked.

    It should look like this:

    enter image description here

    You didn't show this class's code: MyGenioView.cs, but I'm guessing it already defines at least some of what is in MyGenioView1.Designer.cs.

    The bottom line is that you have too many conflicting (partial) classes in too many places. It looks to me like you should have one class (code page) for MyGenioView, and another for the form. Anything else is conflicting.

    P.S. I also wonder if you are confusing WPF constructs with WinForms. They are vastly different. Your use of the word 'View' suggested this to me. I may be wrong.