GenericDictionaryCustomValue Sample
Back to summary
Source
using System.Collections.Generic;
namespace XmlSerializersTest.Samples
{
[Title("Generic dictionary with custom value type")]
public class GenericDictionaryCustomValue
{
public Dictionary<string, OneSimpleProperty> Things { get; set; }
}
}
|
XAML Serializer
<GenericDictionaryCustomValue xmlns="clr-namespace:XmlSerializersTest.Samples;assembly=XmlSerializersTest" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<GenericDictionaryCustomValue.Things>
<OneSimpleProperty Value="1" x:Key="one" />
</GenericDictionaryCustomValue.Things>
</GenericDictionaryCustomValue>
|
Deserialization failed:
System.Windows.Markup.XamlParseException: 'one' attribute in 'http://schemas.microsoft.com/winfx/2006/xaml' namespace is valid only when used with an IDictionary property. Cannot add element to 'Things'; the property value is null. Error at object 'XmlSerializersTest.Samples.OneSimpleProperty', Line 3 Position 34. Error at object 'XmlSerializersTest.Samples.OneSimpleProperty', Line 3 Position 34. ---> System.Windows.Markup.XamlParseException: Cannot add element to 'Things'; the property value is null. Error at object 'XmlSerializersTest.Samples.OneSimpleProperty', Line 3 Position 34.
at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)
at System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext, Int32 lineNumber, Int32 linePosition, String message, Exception innerException)
at System.Windows.Markup.BamlRecordReader.ThrowExceptionWithLine(String message, Exception innerException)
at System.Windows.Markup.BamlRecordReader.ThrowException(String id, String parameter)
at System.Windows.Markup.BamlRecordReader.InitPropertyCollection(BamlCollectionHolder holder, ReaderContextStackData context)
at System.Windows.Markup.BamlRecordReader.GetCollectionHolderFromContext(ReaderContextStackData context, Boolean toInsert)
at System.Windows.Markup.BamlRecordReader.GetDictionaryFromContext(ReaderContextStackData context, Boolean toInsert)
at System.Windows.Markup.BamlRecordReader.SetKeyOnContext(Object key, String attributeName, ReaderContextStackData context, ReaderContextStackData parentContext)
--- End of inner exception stack trace ---
at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)
at System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext, Int32 lineNumber, Int32 linePosition, String message, Exception innerException)
at System.Windows.Markup.BamlRecordReader.ThrowExceptionWithLine(String message, Exception innerException)
at System.Windows.Markup.BamlRecordReader.SetKeyOnContext(Object key, String attributeName, ReaderContextStackData context, ReaderContextStackData parentContext)
at System.Windows.Markup.BamlRecordReader.ReadDefAttributeRecord(BamlDefAttributeRecord bamlDefAttributeRecord)
at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)
at System.Windows.Markup.BamlRecordReader.Read(BamlRecord bamlRecord, Int32 lineNumber, Int32 linePosition)
at System.Windows.Markup.XamlTreeBuilder.BamlRecordWriterSyncUpdate(BamlRecord bamlRecord, Int32 lineNumber, Int32 linePosition)
at System.Windows.Markup.XamlTreeBuilderBamlRecordWriter.WriteBamlRecord(BamlRecord bamlRecord, Int32 lineNumber, Int32 linePosition)
at System.Windows.Markup.BamlRecordWriter.WriteAndReleaseRecord(BamlRecord bamlRecord, XamlNode xamlNode)
at System.Windows.Markup.BamlRecordWriter.WriteDefAttribute(XamlDefAttributeNode xamlDefNode)
at System.Windows.Markup.XamlParser.WriteDefAttribute(XamlDefAttributeNode xamlDefAttributeNode)
at System.Windows.Markup.XamlParser.WriteDefAttributeCore(XamlDefAttributeNode xamlDefAttributeNode)
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