BUG: You may receive a "CS0500" compilation error when you compile code that is generated in the Method Wizard in Visual C# .NET (811599)
The information in this article applies to:
- Microsoft Visual C# .NET (2002)
SYMPTOMSWhen you use the Visual C# .NET Method Wizard to add an abstract method that returns a value, you may receive the following
compilation error: error CS0500: '<your fully
qualified method name>' cannot declare a body because it is marked
abstract CAUSEThe Visual C# .NET Method Wizard generates code for the
method body for abstract methods that return a value. If a method is marked as abstract, the Visual C# .NET Method Wizard sets the MustImplement property to true. Therefore, when the wizard generates code, if the abstract method returns a value, the wizard generates a method body. If
the abstract method has a void return type, the wizard does not generate a
method body. RESOLUTIONTo resolve this problem, delete the generated method body
code from the abstract method. For example, if you use the Visual C# .NET Method Wizard
to generate an abstract method that returns an "int", the wizard generates the following:
public abstract int myAbstractMethod()
{
return 0;
} Remove the code that is generated, and then add a semi-colon at the end
of the function definition. The modified code appears as follows: public abstract int myAbstractMethod(); STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are
listed at the beginning of this article.
Modification Type: | Minor | Last Reviewed: | 1/18/2006 |
---|
Keywords: | kbBug kberrmsg kbwizard KB811599 kbAudDeveloper |
---|
|