Microsoft KB Archive/811599

= BUG: You may receive a &quot;CS0500&quot; compilation error when you compile code that is generated in the Method Wizard in Visual C# .NET =

Article ID: 811599

Article Last Modified on 1/18/2006

-

APPLIES TO


 * Microsoft Visual C# .NET 2002 Standard Edition

-



SYMPTOMS
When 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: '' cannot declare a body because it is marked abstract



CAUSE
The 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.



RESOLUTION
To 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 &quot;int&quot;, 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.



Steps to Reproduce the Behavior
 Start Visual Studio .NET. On the File menu, point to New, and then click Project. Under Project Types, click Visual C# Projects, and then click Console Application under Templates. Type SampleApplication as the project name, and then click OK. To add an abstract class, follow these steps:  In the Class View, right-click SampleApplication, point to Add and then click Add Class.</li> In the Class Wizard, follow these steps: <ol> Type MySampleClass as the class name.</li> Click to select Abstract under Class modifiers section.</li> Click Finish.</li></ol> </li></ol> </li> To add an abstract method, follow these steps: <ol style="list-style-type: lower-alpha;"> In Class View, right-click MySampleClass, point to Add, and then click Add Method.</li> In the Method Wizard, select the return type as int.</li></ol> </li> Type myAbstractMethod as the Method name.</li> Under the Method modifiers section, click to select Abstract.</li> Click Finish.</li> On the Build menu, click Build Solution.</li></ol>

You receive the compilation error that is described in the &quot;Symptoms&quot; section.

Keywords: kberrmsg kbbug kbwizard KB811599

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.