Microsoft KB Archive/943177

= WPF: XamlParseException while loading XMAL written out for derived class =

Article ID: 943177

Article Last Modified on 9/28/2007



Source: Microsoft Support



RAPID PUBLISHING
RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.



Action
You have a base class with a member that is a Dictionary. You also have a derived class that inherits from the base class. After writing out the derived class to a file using XamlWriter.Save, reading the file using XamlReader.Load will raise the unhandled XamlParseException. Howerver, doing the same thing to the base class works properly.



Result
You would see an error and a callstack similar to the following:

XamlParseException was unhandled:

Cannot add content of type 'System.Int32' to an object of type '.'. Error at object 'IntArg', Line  Position .

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.ThrowException(SRID id, String parameter1, String parameter2)

at System.Windows.Markup.BamlRecordReader.SetPropertyValueToParent(Boolean fromStartTag, Boolean& isMarkupExtension)

at System.Windows.Markup.BamlRecordReader.SetPropertyValueToParent(Boolean fromStartTag)

at System.Windows.Markup.BamlRecordReader.ReadElementEndRecord(Boolean fromNestedBamlRecordReader)

at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)

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.WriteElementEnd(XamlElementEndNode xamlElementEndNode)

at System.Windows.Markup.XamlParser.WriteElementEnd(XamlElementEndNode xamlElementEndNode)

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.XamlTreeBuilder.ParseFragment

at System.Windows.Markup.TreeBuilder.Parse

at System.Windows.Markup.XamlReader.XmlTreeBuildDefault(ParserContext pc, Stream stream, XamlParseMode parseMode, Boolean etwTracingEnabled)

at System.Windows.Markup.XamlReader.Load(Stream stream)



Cause
This is a known issue that is being investigated.



Resolution
To work around this issue, you can apply the following attribute to the member that is a Dictionary in the base class:

[DefaultValueAttribute(null)]



MoreInformation


DISCLAIMER
MICROSOFT CORPORATION AND/OR ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY, RELIABILITY, OR ACCURACY OF THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN. ALL SUCH INFORMATION AND RELATED GRAPHICS ARE PROVIDED &quot;AS IS&quot; WITHOUT WARRANTY OF ANY KIND. MICROSOFT AND/OR ITS RESPECTIVE SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THIS INFORMATION AND RELATED GRAPHICS, INCLUDING ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, WORKMANLIKE EFFORT, TITLE AND NON-INFRINGEMENT. YOU SPECIFICALLY AGREE THAT IN NO EVENT SHALL MICROSOFT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, PUNITIVE, INCIDENTAL, SPECIAL, CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF USE, DATA OR PROFITS, ARISING OUT OF OR IN ANY WAY CONNECTED WITH THE USE OF OR INABILITY TO USE THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN, WHETHER BASED ON CONTRACT, TORT, NEGLIGENCE, STRICT LIABILITY OR OTHERWISE, EVEN IF MICROSOFT OR ANY OF ITS SUPPLIERS HAS BEEN ADVISED OF THE POSSIBILITY OF DAMAGES.

Keywords: kbnomt kbrapidpub KB943177

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.