GenericListXamlContentPrivateSetter Sample

Back to summary

Source

using System.Collections.Generic;
using System.ComponentModel;

namespace XmlSerializersTest.Samples
{
    public class GenericListXamlContentPrivateSetter
    {
        public GenericListXamlContentPrivateSetter()
        {
            Strings = new List<string> {"foo", "bar", "baz"};
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public List<string> Strings { get; private set; } 
    }
}

Standard Serializer

System.InvalidOperationException: Unable to generate a temporary class (result=1).
error CS0200: Property or indexer 'XmlSerializersTest.Samples.GenericListXamlContentPrivateSetter.Strings' cannot be assigned to -- it is read only
error CS0200: Property or indexer 'XmlSerializersTest.Samples.GenericListXamlContentPrivateSetter.Strings' cannot be assigned to -- it is read only

   at System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence)
   at System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Assembly assembly, Hashtable assemblies)
   at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence)
   at System.Xml.Serialization.XmlSerializer.GenerateTempAssembly(XmlMapping xmlMapping, Type type, String defaultNamespace)
   at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)
   at System.Xml.Serialization.XmlSerializer..ctor(Type type)
   at XmlSerializersTest.Serializers.StandardXmlSerializer.Serialize(Object obj, XmlWriter writer) in C:\Ivan\dev\XmlSerializersTest\XmlSerializersTest\Serializers\StandardXmlSerializer.cs:line 13
   at XmlSerializersTest.SampleProcessor.SerializeToString(Object obj, IXmlSerializer serializer) in C:\Ivan\dev\XmlSerializersTest\XmlSerializersTest\SampleProcessor.cs:line 162
   at XmlSerializersTest.SampleProcessor.RecordSerializationResults(Object obj, IXmlSerializer serializer) in C:\Ivan\dev\XmlSerializersTest\XmlSerializersTest\SampleProcessor.cs:line 115

Deserialization skipped

XAML Serializer

<GenericListXamlContentPrivateSetter xmlns="clr-namespace:XmlSerializersTest.Samples;assembly=XmlSerializersTest" xmlns:s="clr-namespace:System;assembly=mscorlib">
  <GenericListXamlContentPrivateSetter.Strings>
    <s:String>foo</s:String>
    <s:String>bar</s:String>
    <s:String>baz</s:String>
  </GenericListXamlContentPrivateSetter.Strings>
</GenericListXamlContentPrivateSetter>

Deserialization failed:

System.Windows.Markup.XamlParseException: property 'GenericListXamlContentPrivateSetter.Strings' cannot be set because it does not have an accessible set accessor. Line '2' Position '4'.
   at System.Windows.Markup.XamlReaderHelper.Read(XamlNode& xamlNode)
   at System.Windows.Markup.XamlParser.ReadXaml(Boolean singleRecordMode)
   at System.Windows.Markup.TreeBuilderXamlTranslator._Parse()
   at System.Windows.Markup.XamlParser.Parse()
   at System.Windows.Markup.XamlTreeBuilder.ParseFragment()
   at System.Windows.Markup.TreeBuilder.Parse()
   at System.Windows.Markup.XamlReader.XmlTreeBuildDefault(ParserContext pc, XmlReader reader, Boolean wrapWithMarkupCompatReader, XamlParseMode parseMode, Boolean etwTracingEnabled)
   at System.Windows.Markup.XamlReader.Load(XmlReader reader)
   at XmlSerializersTest.Serializers.XamlSerializer.Deserialize(XmlReader reader, Type typeToDeserialize) in C:\Ivan\dev\XmlSerializersTest\XmlSerializersTest\Serializers\XamlSerializer.cs:line 18
   at XmlSerializersTest.SampleProcessor.DeserializeFromString(String xml, IXmlSerializer serializer, Type typeToDeserialize) in C:\Ivan\dev\XmlSerializersTest\XmlSerializersTest\SampleProcessor.cs:line 198
   at XmlSerializersTest.SampleProcessor.RecordDeserializationResults(String xml, IXmlSerializer serializer, Type typeToDeserialize) in C:\Ivan\dev\XmlSerializersTest\XmlSerializersTest\SampleProcessor.cs:line 181

WCF Serializer

<GenericListXamlContentPrivateSetter xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/XmlSerializersTest.Samples" />

WCF-ref Serializer

<GenericListXamlContentPrivateSetter xmlns:i="http://www.w3.org/2001/XMLSchema-instance" z:Id="1" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" xmlns="http://schemas.datacontract.org/2004/07/XmlSerializersTest.Samples" />