The Sgen.exe tool generates different results for classes that have public getter methods and nonpublic setter methods for some properties in different versions of the .NET Framework 2.0

The Sgen.exe tool generates different results for classes that have public getter methods and nonpublic setter methods for some properties in different versions of the .NET Framework 2.0

Article ID : 956847
Last Review : August 19, 2008
Revision : 1.0

SYMPTOMS

You have some classes that have public getter methods and nonpublic setter methods for some properties. When you use the XML Serializer Generator tool (Sgen.exe), different results are generated in different versions of the Microsoft .NET Framework 2.0.

When you run the Sgen.exe tool on a computer that has the .NET Framework 2.0 Service Pack 1 (SP1) installed, you receive the following exception:

Error: Unable to generate a temporary class (result=1). error CS0200: Property or indexer ‘PropertyName‘ cannot be assigned to — it is read only

When you run the Sgen.exe tool on a computer that has the .NET Framework 2.0 Service Pack 2 (SP2) installed, no exception occurs. However, the results that you obtain by using the XML Serializer Generator tool will change in later releases of the .NET Framework 2.0 SP2. At that time, applications that rely on this feature will not work correctly.

Back to the top

CAUSE

The exception does not occur because a feature was added to the ASMX Web services. The feature is used to serialize types that have nonpublic setter methods for properties in the .NET Framework 2.0 SP2.

However, the feature introduces a regression in a particular scenario in which certain types cannot be serialized. Therefore, the feature will be removed in later releases of the .NET Framework 2.0 SP2.

Back to the top

WORKAROUND

To work around this problem, add a friend relationship in the original assembly to the assembly that you create by using the Sgen.exe tool. To do this, add the following line of code to the AssemblyInfo.cs file of the original assembly:

[assembly: InternalsVisibleTo(<AssemblyName>.XmlSerializers, PublicKeyToken=null)]

When you do this, you receive the following message as expected:

Serialization Assembly Name: AssemblyName.XmlSerializers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.

Generated serialization assembly for assembly AssemblyDirectory –> directory of SerializationAssemblyDirectory.

Back to the top

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the Applies to section.

Back to the top

MORE INFORMATION

For more information about the Sgen.exe tool, visit the following Microsoft Developer Network (MSDN) Web site:

http://msdn.microsoft.com/en-us/library/bk3w6240(VS.80).aspx (http://msdn.microsoft.com/en-us/library/bk3w6240(VS.80).aspx)

Back to the top


APPLIES TO
• Microsoft .NET Framework 2.0

Back to the top

Keywords: 
kbexpertiseadvanced kbprb KB956847

Back to the top

 

Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
Microsoft Corporation. All rights reserved. Terms of Use | Trademarks


You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

AddThis Social Bookmark Button

Leave a Reply

*
To prove that you're not a bot, enter this code
Anti-Spam Image