user3200169 user3200169 - 1 year ago 29
C# Question

Why im getting error on the line InitializeComponent();?

I have this Usercontrol, I created and Im getting error on

InitializeComponent


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech.Synthesis;

namespace RssNews
{
public partial class
FeederControl : UserControl
{
SpeechSynthesizer speaker;
Label[] list = new Label[5];
int jump = 0;
private IContainer components;

public string[] NewsTextFeed { get; set; }
public Color[] TextColor { get; set; }

private int _spacing = 10;
public int Spacing
{
get { return _spacing; }
set { _spacing = value; }
}

public void NewsFeederControl()
{
InitializeComponent();
speaker = new SpeechSynthesizer();
Init();
}


The error/s:


Error 29 The call is ambiguous between the following methods or
properties: 'RssNews.FeederControl.InitializeComponent()' and
'RssNews.FeederControl.InitializeComponent()'


Then in the designer of the UserControl:


Error 31 Ambiguity between 'RssNews.FeederControl.components' and
'RssNews.FeederControl.components'


This is the designer code:

namespace RssNews
{
partial class FeederControl
{
/// <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.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// FeederControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.AntiqueWhite;
this.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.Name = "FeederControl";
this.Size = new System.Drawing.Size(146, 146);
this.Load += new System.EventHandler(this.FeederControl_Load);
this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.Timer timer1;
}
}


Im getting erorrs same error meassage on all components in the designer.cs code.
And also


Error 2 Type 'RssNews.FeederControl' already defines a member called
'InitializeComponent' with the same parameter types


This control is working good on another project i did same code. I just changed the namespaces names for this project. The one before was mws and this one is RssNews

How can i fix the errors ?

pid pid
Answer Source

First thing: you have a different constructor name then the class name. Second, have you tried to debug it? You posted way too much code. Trim it down to the relevant pieces.

Solution:

You have 2 partials that are merged into one, and the function InitializeComponent() defined twice. You must define it only in one of the two partials. Keep it where VS put it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download