Product:
Search Type:

[FIX] Visual Studio 2005 - Get/Set Method Name Conflict

Article ID: 2268 
Last Review: Oct,18 2007
APPLIES TO:
  • Virtuozzo for Windows 3.5.1 SP1

SYMPTOMS

C# compiler produces the following error during Visual Studio Project compilation:

error CS0542: 'set_xxx': member names cannot be the same as their enclosing type

CAUSE

Microsoft Visual C# .NET may produce errors when generating the client code from WSDL similar to the following example:

<xs:element name="set_xxx">
  <xs:complexType>
    <xs:sequence> 
      <xs:element name="xxx" type="XXXtype" />
     </xs:sequence>
   </xs:complexType>
 </xs:element>


Note that the function set_xxx has a parameter xxx. Microsoft Visual C# .NET will generate the following code:

public partial class set_xxx {
    private string xxxField;
    /// <remarks/>
    public string xxx {
        get {
            return this.xxxField;
        }
        set {
            this.xxxField = value;
        }
    }
}

As you can see, the function has the same name as the class name. This causes the C# compiler to produce the error above.

RESOLUTION

Create a batch file wsdlc.bat, for example, containing the following code and save it in your project directory:

setlocal

set WS=%1Web References\%3

copy "%WS%\Reference.map" "%WS%\Reference.discomap"

"%VS80COMNTOOLS%\..\..\SDK\v2.0\Bin\wsdl.exe" /l:CS /fields /out:"%WS%\Reference.cs" /n:%2.%3 "%WS%\Reference.discomap"


del "%WS%\Reference.discomap"

endlocal

exit /b 0

Main part of this script is a calling of wsdl.exe - WSDL compiler - with option /fields. It force compiler don't generate properties and use fields:

public partial class set_xxx {
    private string xxx;
}


The file generates the new Reference.cs file (the file containing the proxy classes) fixing the problem described above by generating the regular properties instead of C#-style get/set fields. Do not try to run the file. It will by run automatically after we complete the rest of the steps.

In the Microsoft Visual C# .NET development environment, select Project > Properties menu item. Select Build Events option in the left pane. Now in the right pane, modify the parameter Pre-build Event Command Line to contain the following line:

$(ProjectDir)wsdlc.bat $(ProjectDir) $(ProjectName) VZA


Where VZA - is a namespace for generated classes.

Note:
Make sure that the Reference.cs file is not currently opened in the IDE, otherwise the compiler will use it instead of the new file that will be generated by our batch file.

Select the Build > Build Solution menu option to build your solution. This will take longer than usual because the wsdlc.bat file that we created will re-generate the proxy classes.

After the build is completed, the Reference.cs file will contain the newly generated stubs. At this point you can remove or comment out the entry that used in the Project > Properties > Pre-build Event Command Line option. If you do not, the stubs will be re-generated every time you build your solution.


If you decide to update the client code from WSDL located on our Web server again, make sure that you repeat the steps described here again.

Additional information

The request describing this defect was submitted to Microsoft: #FDBK46565

Please provide feedback on this article

Did this article help you solve your issue?
Yes
No
Partially
I do not know yet
 
Strongly Agree   Strongly Disagree
  9 8 7 6 5 4 3 2 1
The article is easy to understand
The article is accurate
Additional Comments:
*Please provide us with your email address in case we need to contact you.
*Please type the code you can see.
* - required fields