Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 956847 - Last Review: August 19, 2008 - Revision: 1.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
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.
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.
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.
STATUS
Microsoft
has confirmed that this is a problem in the Microsoft products that are listed
in the "Applies to" section.
MORE INFORMATION
For
more information about the Sgen.exe tool, visit the following Microsoft
Developer Network (MSDN) Web site:
APPLIES TO
- Microsoft .NET Framework 2.0
| kbexpertiseadvanced kbprb KB956847 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
Be the first to leave feedback, to help others about this knowledge base
article.
(Optional) Name
(Optional)
Public URL Or Email
Comments
No
HTML -- Text Only Please