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

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