locked
RichTextBox Serialization RRS feed

  • Question

  • Hi I am using Silverlight RichTextBox on my project and I am wondering can serialize RichTextBox. I am using this code but I get an error.

     

    XmlSerializer xs = new XmlSerializer(typeof(RichTextBox));
          StringWriter sw = new StringWriter();
          using (var memoryStream = new MemoryStream())
          {
            xs.Serialize(memoryStream,rtb);
          }
    

    I did get error on the first line

     

    System.InvalidOperationException was unhandled by user code

      Message=There was an error reflecting type 'System.Windows.Controls.RichTextBox'.

      StackTrace:

           at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter)

           at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, RecursionLimiter limiter)

           at System.Xml.Serialization.XmlReflectionImporter.ImportElement(TypeModel model, XmlRootAttribute root, String defaultNamespace, RecursionLimiter limiter)

           at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(Type type, XmlRootAttribute root, String defaultNamespace)

           at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)

           at System.Xml.Serialization.XmlSerializer..ctor(Type type)

           at SilverlightTextEditor.MainPage.btnSave_Click(Object sender, RoutedEventArgs e)

           at System.Windows.Controls.Primitives.ButtonBase.OnClick()

           at System.Windows.Controls.Button.OnClick()

           at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)

           at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)

           at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)

      InnerException: System.NotSupportedException

           Message=Cannot serialize member System.Windows.FrameworkElement.Resources of type System.Windows.ResourceDictionary, because it implements IDictionary.

           StackTrace:

                at System.Xml.Serialization.TypeScope.GetDefaultIndexer(Type type, String memberInfo)

                at System.Xml.Serialization.TypeScope.GetCollectionElementType(Type type, String memberInfo)

                at System.Xml.Serialization.TypeScope.ImportTypeDesc(Type type, MemberInfo memberInfo, Boolean directReference)

                at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError)

                at System.Xml.Serialization.StructModel.GetPropertyModel(PropertyInfo propertyInfo)

                at System.Xml.Serialization.StructModel.GetFieldModel(MemberInfo memberInfo)

                at System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter)

                at System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel model, String ns, Boolean openModel, XmlAttributes a, RecursionLimiter limiter)

                at System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter)

                at System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel model, String ns, Boolean openModel, XmlAttributes a, RecursionLimiter limiter)

                at System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter)

                at System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel model, String ns, Boolean openModel, XmlAttributes a, RecursionLimiter limiter)

                at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter)

           InnerException: 


    Computer Engineer
    Tuesday, July 5, 2011 1:08 PM