FIX: You receive the "Does not implement interface member 'System.Collections.IEnumerable.GetEnumerator()'" error message when you try to build a Web Control Library project (836127)



The information in this article applies to:

  • Microsoft Visual C# .NET (2002)

SYMPTOMS

You receive an error message when you try to build a Web Control Library project in Microsoft Visual C# .NET 2002. Specifically, if the project contains a Web server control that implements the IDictionary interface, you receive an error message after the Implement Interface command runs. The error message that you receive may be similar to the following:

WebControlLibrary1.WebCustomControl1' does not implement interface member 'System.Collections.IEnumerable.GetEnumerator()'. 'WebControlLibrary1.WebCustomControl1.GetEnumerator()' is either static, not public, or has the wrong return type.

Note The placeholders in this error message are as follows:
  • WebControlLibrary1 is a placeholder for the name of your namespace.
  • WebCustomControl1 is a placeholder for the class name of your Web server control.

CAUSE

In Visual C# .NET 2002, the Implement Interface command does not implement all methods of an interface if any other methods that have the same name and parameters exist in another interface that a class implements. This behavior occurs although the methods may have different return data types.

For example, the Implement Interface command implements the GetEnumerator method of the IDictionary interface. However, the Implement Interface command does not implement the GetEnumerator method of the IEnumerable interface, although the methods have different return data types. Therefore, you experience the symptoms that are described in this article.

RESOLUTION

To resolve this behavior, add the following code to your Web server control class file after the code that the Implement Interface command generates:
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
	return null;
}

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in Microsoft Visual C# .NET 2003.

MORE INFORMATION

Generic scenario

In Visual C# .NET 2002, the Implement Interface command does not implement all methods of an interface if any other methods that have the same name and parameters exist in another interface that a class implements. Therefore, some methods of interfaces that the class inherits from may not be implemented. Therefore, when you try to build a project that contains such a class, you may receive an error message.
For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

811601 BUG: Visual C# .NET Implement Interface command does not implement different declarations with same signature

Steps to reproduce the behavior

  1. Start Visual Studio .NET 2002.
  2. Use Visual C# .NET to create a Web Control Library project. By default, the WebControlLibrary1 project is created together with the WebCustomControl1.cs file.
  3. In the WebCustomControl1.cs file, locate the following code:
    public class WebCustomControl1 : System.Web.UI.WebControls.WebControl
  4. Replace the code that you located in the previous step with the following code so that your Web server control also inherits from the IDictionary interface:
    public class WebCustomControl1 : System.Web.UI.WebControls.WebControl, System.Collections.IDictionary
  5. Open Class View.
  6. Expand WebControlLibrary1, expand WebControlLibrary1, expand WebCustomControl1, and then expand Bases and Interfaces.
  7. Right-click IDictionary, point to Add, and then click Implement Interface.
  8. On the Build menu, click Build WebControlLibrary1.

    You receive the error message that is mentioned in the "Symptoms" section of this article.

Modification Type:MinorLast Reviewed:1/18/2006
Keywords:kbfix kbCodeGen kbInheritance kbControl kbCollections kbClassView KB836127 kbAudDeveloper