<p>I've seen quite a few posts on changes in .NET 3.5 SP1, but stumbled into one that I've yet to see documentation for yesterday.  I had code working just fine on my machine, from VS, msbuild command line, everything, but it failed on the build server (running .NET 3.5 RTM).</p>

<pre><code>[XmlRoot("foo")]
public class Foo
{
    static void Main()
    {
        XmlSerializer serializer = new XmlSerializer(typeof(Foo));

        string xml = @"&lt;foo name='ack' /&gt;";
        using (StringReader sr = new StringReader(xml))
        {
            Foo foo = serializer.Deserialize(sr) as Foo;
        }
    }

    [XmlAttribute("name")]
    public string Name { get; set; }

    public Foo Bar { get; private set; }
}
</code></pre>

<p>In SP1, the above code runs just fine. In RTM, you get an InvalidOperationException:</p>

<blockquote>
  <p>Unable to generate a temporary class (result=1).
  error CS0200: Property or indexer 'ConsoleApplication2.Foo.Bar' cannot be assign to -- it is read only</p>
</blockquote>

<p>Of course, all that's needed to make it run under RTM is adding [XmlIgnore] to the Bar property.</p>

<p>My google fu is apparently not up to finding documentation of these kinds of changes. Is there a change list anywhere that lists this change (and similar under-the-hood changes that might jump up and shout "gotcha")?  Is this a bug or a feature? </p>

<p><strong>EDIT</strong>: In SP1, if I added a <code>&lt;Bar /&gt;</code> element, or set [XmlElement] for the Bar property, it won't get deserialized.  It doesn't fail pre-SP1 when it tries to deserialize--it throws an exception when the XmlSerializer is constructed.</p>

<p>This makes me lean more toward it being a bug, especially if I set an [XmlElement] attribute for Foo.Bar. If it's unable to do what I ask it to do, it should be throwing an exception instead of silently ignoring Foo.Bar.  Other invalid combinations/settings of XML serialization attributes result in an exception.</p>

<p><strong>EDIT</strong>: Thank you, TonyB, I'd not known about setting the temp files location. For those that come across similar issues in the future, you do need an additional config flag:</p>

<pre><code>&lt;system.diagnostics&gt;
  &lt;switches&gt;
    &lt;add name="XmlSerialization.Compilation" value="1" /&gt;
  &lt;/switches&gt;
&lt;/system.diagnostics&gt;
&lt;system.xml.serialization&gt;
  &lt;xmlSerializer tempFilesLocation="c:\\foo"/&gt;
&lt;/system.xml.serialization&gt;
</code></pre>

<p>Even with setting an [XmlElement] attribute on the Bar property, no mention was made of it in the generated serialization assembly--which fairly firmly puts this in the realm of a silently swallowed error (aka, a bug). Either that or the designers have decided [XmlIgnore] is no longer necessary for properties that can't be set--and you'd expect to see that in release notes, <a href="http://support.microsoft.com/kb/951847" rel="nofollow noreferrer">change lists</a>, or the <a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlignoreattribute.aspx" rel="nofollow noreferrer">XmlIgnoreAttribute documentation</a>.</p>

[{'answer_id': 35223, 'author': 'TonyB', 'author_id': 3543, 'author_profile': 'https://Stackoverflow.com/users/3543', 'pm_score': 3, 'selected': True, 'text': '<p>In SP1 does the foo.Bar property get properly deserialized?</p>\n\n<p>In pre SP1 you wouldn\'t be able to deserialize the object because the set method of the Bar property is private so the XmlSerializer doesn\'t have a way to set that value.  I\'m not sure how SP1 is pulling it off.</p>\n\n<p>You could try adding this to your web.config/app.config</p>\n\n<pre><code>&lt;system.xml.serialization&gt; \n  &lt;xmlSerializer tempFilesLocation="c:\\\\foo"/&gt; \n&lt;/system.xml.serialization&gt; \n</code></pre>\n\n<p>That will put the class generated by the XmlSerializer into c:\\foo so you can see what it is doing in SP1 vs RTM</p>\n'}, {'answer_id': 35363, 'author': 'Jesse C. Slicer', 'author_id': 3312, 'author_profile': 'https://Stackoverflow.com/users/3312', 'pm_score': 0, 'selected': False, 'text': "<p>I rather like this new (?) behavior because the XML document doesn't have any mention of Bar in it, so the deserializer should not even be attempting to set it.</p>\n"}]
['https://Stackoverflow.com/questions/34925', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2314/']