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



The information in this article applies to:

  • Microsoft Visual C# .NET (2002)

SYMPTOMS

The Microsoft Visual C# .NET Implement Interface command does not implement functions that have the same signature. However, the return types of the functions are different when you implement more than one interface. You may receive the following compilation error message when you try to build the project:
NameSpace.Class Name does not implement interface member Member Name'. NameSpace.ClassName.Member Name is either static, not public, or has wrong return type.
Where Class Name is the name of the class and Member Name is the name of the method with the same signature.

CAUSE

In Microsoft Visual Studio .NET 2002, the Implement Interface command does not implement all the functions of an interface if any other function with the same signature already exists (even if the functions have different return types) in another interface that is implemented by the class. As a result, some of the functions with the same signature are not implemented when you use the Implement Interface command. Therefore, you may receive a compilation error when you try to compile your project.

WORKAROUND

To work around this problem, manually add the implementation of the function that was not implemented by the Implement Interface command.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug had been fixed in Microsoft Visual Studio .NET 2003.

MORE INFORMATION


Steps to Reproduce the Behavior
  1. Create a new Microsoft Visual C# .NET Console Application Project, and name the project TestApplication. By default, Class1.cs is created.
  2. Replace the code of the Class1.cs with the following code:
    using System;
    
    namespace TestApplication
    {
    	interface I1
    	{
    		int Function1();
    	}
    	interface I2
    	{
    		int Function2();
    		float Function1();
    	}
    	class Class1:I1,I2
    	{
    		[STAThread]
    		static void Main(string[] args)
    		{
    			Console.WriteLine("Test Application");		
    		}
    	}
    }
    
    Class1 implements I1 and I2 interfaces.
  3. On the View menu, click Class View.
  4. Expand TestApplication, expand Class1, and then expand Bases and Interfaces. Interface I1 and Interface I2 are displayed.
  5. To add implementation of Interface I1 to Class1, right-click Interface I1, point to Add, and then click Implement Interface.
  6. To add implementation of Interface I2 to Class1, right-click Interface I2, point to Add, and then click Implement Interface. This only implements the Function2 function for Interface I2. The Function1 function for Interface I2 is not implemented.
  7. On the Build menu, click Build Solution to compile the project. You receive the error message that is described in the "Symptoms" section of this article.
  8. To build the project successfully, manually implement the missing function of Interface I2. To do this, add the following code to Class1:
    		float I2.Function1()
    		{
    			return 0;
    		}
  9. Repeat step 8 to successfully build the project.

Modification Type:MajorLast Reviewed:1/18/2006
Keywords:kberrmsg kbMsg kbCompiler kbInheritance kbbug KB811601 kbAudDeveloper