MissingProperty Sample

Back to summary

Source

#if HELPER_ASSEMBLY
using System;

namespace XmlSerializersTest.Samples
{
    public class MissingProperty
    {
        public string PropertyA { get; set; }
#if VERSION_1_0
        public string PropertyB { get; set; }

        public static MissingProperty GetInstance() 
        {
            return new MissingProperty { PropertyA = "a", PropertyB = "b" };
        }
#endif
    }
}
#endif

Standard Serializer

<MissingProperty>
  <PropertyA>a</PropertyA>
  <PropertyB>b</PropertyB>
</MissingProperty>

XAML Serializer

<MissingProperty PropertyA="a" PropertyB="b" xmlns="clr-namespace:XmlSerializersTest.Samples;assembly=HelperAssembly" />

Deserialization failed:

System.Windows.Markup.XamlParseException: The property 'PropertyB' does not exist in XML namespace 'clr-namespace:XmlSerializersTest.Samples;assembly=HelperAssembly'. Line '1' Position '32'.
   at System.Windows.Markup.XamlParser.ThrowExceptionWithLine(String message, Int32 lineNumber, Int32 linePosition)
   at System.Windows.Markup.XamlParser.ThrowException(String id, String value1, String value2, Int32 lineNumber, Int32 linePosition)
   at System.Windows.Markup.XamlParser.WriteUnknownAttribute(XamlUnknownAttributeNode xamlUnknownAttributeNode)
   at System.Windows.Markup.XamlParser.ProcessXamlNode(XamlNode xamlNode, Boolean& cleanup, Boolean& done)
   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

<MissingProperty xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/XmlSerializersTest.Samples">
  <PropertyA>a</PropertyA>
  <PropertyB>b</PropertyB>
</MissingProperty>

WCF-ref Serializer

<MissingProperty 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">
  <PropertyA z:Id="2">a</PropertyA>
  <PropertyB z:Id="3">b</PropertyB>
</MissingProperty>