FIX: You receive an "Error CS1513" error message when you try to compile code that is generated by the Implement Interface Wizard in Visual Studio .NET (315740)



The information in this article applies to:

  • Microsoft Visual Studio .NET (2002), Professional Edition

This article was previously published under Q315740

SYMPTOMS

The code generated by the Implement Interface Wizard does not compile correctly. Instead, you receive the following error message:
c:\my samples\q315740\class1.cs(37,2): error CS1513: } expected

CAUSE

This behavior occurs only with a class that derives from an interface and for which no methods or properties are implemented as yet.

The Implement Interface code generator places the closing curly brace for the class in the same line as the #endregion directive. The #region directive lets you specify a block of code that you can expand or collapse when you use the outlining feature of the Visual Studio Code Editor.

RESOLUTION

To resolve this issue, move the curly brace next to the #endregion directive.

NOTE: If a method or property were already implemented in your class, you would not encounter this issue.

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 Studio .NET (2003), Professional Edition.

MORE INFORMATION

Steps to Reproduce the Problem

  1. Create a new C# console application.
  2. Add an empty class that implements an interface. Make sure that no methods or properties are defined. Also, make sure that you have referenced the assembly that defines the interface. For example:
    //Add the following to the top of your file
    using System.Collections;
    class Class2 : IEnumerable
    {
    		
    }
    					
  3. Go to ClassView. Open the Class2 node, open the Bases and Interfaces node underneath it, and then select the IEnumerable interface. Right-click, point to the Add menu, and then click Implement Interface.

    The following code should be generated:
    #region Implementation of IEnumerable
    		public System.Collections.IEnumerator GetEnumerator()
    		{
    			return null;
    		}
    	
    		#endregion}//<--- Take this curly brace to the next line
    					
  4. Compile the application.

Modification Type:MinorLast Reviewed:8/24/2005
Keywords:kbvs2002sp1sweep kbfix kbbug kberrmsg kbnofix KB315740