title: The call is ambiguous between the following methods: Identical.NameSpace.InitializeComponent() and Identical.NameSpace.InitializeComponent()
body: <p>Ok, I suspect this might be a Visual Studio thing, but there must be some reason for this. I created from the list of default items a ListBox (Right Click on project, or folder in project -> Add -> New Item -> Xaml ListBox). Immediately I get a red squiggly line with the error: </p>
  
  <blockquote>
    <p>"Error    2   The call is ambiguous between the following methods or
    properties: 'Identical.NameSpace.ListBox1.InitializeComponent()' and
    'Identical.NameSpace.ListBox1.InitializeComponent()'  C:\Documents and
    Settings\ouflak\My Documents\Visual Studio
    2010\Projects\Identical\NameSpace\ListBox1.xaml.cs   27"</p>
  </blockquote>
  
  <p>All of the code in question is auto-generated and the reason for the error is because of a conflict between two auto-generated files: ListBox1.g.cs and ListBox1.designer.cs where <code>public void</code> InitializeComponent() is declared in both. Naturally the code cannot compile under this circumstance. It is simple enough to just delete the ListBox1.designer.cs and move on I suppose. <strong>But my question: Why is this code auto-generated with this error? I would expect anything auto-generated to be able to build and compile without having to touch the project or any code. For just about every other toobox item that you can add, this is the case. So why generate this code with the built-in error? Are we supposed to find some way to make this work? Is this code merely a suggestion and it is up to the IDE user/developer to hammer out the details?</strong></p>
  
  <p>Here is the generated code:
  ListBox1.xaml:</p>
  
  <pre><code>&lt; ?xml version="1.0" encoding="utf-8" ? &gt; 
  &lt; ListBox
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:xc="http://ns.neurospeech.com/xaml"
      xmlns:sys="clr-namespace:System;assembly=mscorlib"
      x:Class="Identical.NameSpace.ListBox1"
      &gt;
      &lt;sys:String&gt;Item 1&lt;/sys:String&gt;
      &lt;sys:String&gt;Item 2&lt;/sys:String&gt;
      &lt;sys:String&gt;Item 3&lt;/sys:String&gt;
  &lt; /ListBox&gt;
  </code></pre>
  
  <p>ListBox1.g.cs:</p>
  
  <pre><code>namespace Identical.Namespace
  {
      /// &lt;summary&gt;
      /// ListBox1
      /// &lt;/summary&gt;
      [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
      public partial class ListBox1 : System.Windows.Controls.ListBox, System.Windows.Markup.IComponentConnector {
  
          private bool _contentLoaded;
  
          /// &lt;summary&gt;
          /// InitializeComponent
          /// &lt;/summary&gt;
          [System.Diagnostics.DebuggerNonUserCodeAttribute()]
          public void InitializeComponent() {
              if (_contentLoaded) {
              return;
              }
              _contentLoaded = true;
              System.Uri resourceLocater = new System.Uri("/MyProject;component/namespace/listbox1.xaml", System.UriKind.Relative);
  
              #line 1 "..\..\..\namespace\ListBox1.xaml"
              System.Windows.Application.LoadComponent(this, resourceLocater);
  
              #line default
              #line hidden
          }
  
          [System.Diagnostics.DebuggerNonUserCodeAttribute()]
          [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
          [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")]
          [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
          [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
          void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)     {
          this._contentLoaded = true;
          }
      }
  }
  </code></pre>
  
  <p>ListBox1.designer.cs:</p>
  
  <pre><code>namespace Identical.NameSpace
  {
      using System;
  
      public partial class ListBox1 : System.Windows.Controls.ListBox
      {
          private void InitializeComponent()
          {
              // Pre Statements...
              string string1 = "Item 1";
              string string2 = "Item 2";
              string string3 = "Item 3";
              // Statements...
              this.BeginInit();
              this.Items.Add(string1);
              this.Items.Add(string2);
              this.Items.Add(string3);
              this.EndInit();
              // Post Statements...
          }
      }
  }
  </code></pre>
  
  <p>and lastly the ListBox1.xaml.cs (only modified to prevent XML documentation and Stylecop warnings):</p>
  
  <pre><code>namespace Identical.NameSpace
  {
      /// &lt;summary&gt;
      /// ListBox1 class
      /// &lt;/summary&gt;
      public partial class ListBox1 : ListBox
      {
          /// &lt;summary&gt;
          /// Initializes a new instance of the ListBox1 class
          /// &lt;/summary&gt;
          public ListBox1()
          {
              this.InitializeComponent();
          }
      }
  }
  </code></pre>
  
  <p>That's it. This is the code entirely in its virgin auto-generated state with the exception of the comments I put into the xaml.cs file.</p>
  
  <p>I've searched this site and the internet a bit, but no one seems to have explained this behavior. I will probably just delete the designer.cs code and move on. But if anybody knows why this is here in the first place, or if it is indeed a bug in Visual Studio 2010 professional, I'd really like to know.</p>