Jump to content
Software FX Community

Chart Serialization


MMCCPaulEden

Recommended Posts

Hi

I'm trying to track down a serialization issue and currently things are pointing at ChartFX - during serialization I get the following error:

A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in System.dll

Property accessor 'ReadTimeout' on object 'System.IO.MemoryStream' threw the following exception:'Timeouts are not supported on this stream.'

 

Anyone else having similar issues?

 

Thanks

 

Paul

 

 

Link to comment
Share on other sites

Hi

Chart serialization is benf fired by another 3rd party component, which acts as a container for the Chart control.  As above, only serialization in conjunction with a ChartFX chart generates the exception.

After a small amount of research on the web, I have seen comments saying that the error message is misleading and (in one instance) was actually being thrown from a FileStream object:

 

http://www.pcreview.co.uk/forums/thread-2330646.php

Is there anything in the ChartFX chart object that could be doing this?

 

Thanks

 

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

Hi Juan

We had intended to build this up a little at a time to provide replication code, but tripped at the blocks...

In an attempt to serialize a Chart we started with the following line: 

XmlSerializer

oXS = new XmlSerializer(typeof(ChartFX.WPF.Chart))

 

But it generates an exception:

 

System.InvalidOperationException was unhandled  Message="There was an error reflecting type 'ChartFX.WPF.Chart'."  Source="System.Xml"  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 ChartFX_Serialize.Window1.btnSerialize_Click(Object sender, RoutedEventArgs e) in C:\Users\Neutrino_1\AppData\Local\Temporary Projects\ChartFX_Serialize\Window1.xaml.cs:line 31 at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.UIElement.RaiseEvent(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.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent) at System.Windows.UIElement.CrackMouseButtonEventAndReRaiseEvent(DependencyObject sender, MouseButtonEventArgs e) at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted) at System.Windows.Input.InputManager.ProcessStagingArea() at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input) at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel) at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter) at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.Run() at System.Windows.Application.RunDispatcher(Object ignore) at System.Windows.Application.RunInternal(Window window) at System.Windows.Application.Run(Window window) at System.Windows.Application.Run() at ChartFX_Serialize.App.Main() in C:\Users\Neutrino_1\AppData\Local\Temporary Projects\ChartFX_Serialize\obj\Debug\App.g.cs:line 0 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()  InnerException: System.InvalidOperationException Message="There was an error reflecting property 'InputBindings'." Source="System.Xml" StackTrace:   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.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: System.InvalidOperationException   Message="There was an error reflecting type 'System.Windows.Input.InputBinding'."   Source="System.Xml"   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.CreateArrayElementsFromAttributes(ArrayMapping arrayMapping, XmlArrayItemAttributes attributes, Type arrayElementType, String arrayElementNs, RecursionLimiter limiter) at System.Xml.Serialization.XmlReflectionImporter.ImportArrayLikeMapping(ArrayModel model, String ns, RecursionLimiter limiter) at System.Xml.Serialization.XmlReflectionImporter.ImportAccessorMapping(MemberMapping accessor, FieldModel model, XmlAttributes a, String ns, Type choiceIdentifierType, Boolean rpc, Boolean openModel, RecursionLimiter limiter) at System.Xml.Serialization.XmlReflectionImporter.ImportFieldMapping(StructModel parent, FieldModel model, XmlAttributes a, String ns, RecursionLimiter limiter) at System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping mapping, StructModel model, Boolean openModel, String typeName, RecursionLimiter limiter)   InnerException: System.InvalidOperationException Message="Cannot serialize member 'System.Windows.Input.InputBinding.Command' of type 'System.Windows.Input.ICommand', see inner exception for more details." Source="System.Xml" StackTrace:   at System.Xml.Serialization.StructModel.CheckSupportedMember(TypeDesc typeDesc, MemberInfo member, Type type)   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.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter) InnerException: System.NotSupportedException   Message="Cannot serialize member System.Windows.Input.InputBinding.Command of type System.Windows.Input.ICommand because it is an interface."   InnerException:

Link to comment
Share on other sites

  • 2 weeks later...

We have been working on serialization for some time on 2 approaches

1) saving and loading from XML. Note that this approach does not serialize the chart data, also because of WPF limitations, if you provide user defined data templates (to style how the bars are painted for example) this will not work as bindings will be lost. This is accomplished using the Export/Import methods.

2) a Clone method, this method uses the XML serialization but transfers the data as well as any user data templates. We also have some optimizations to make sure data does not have to be reprocessed.

The clone method is used internally on our zoom code.

Please let us know if this works for you.

Regards,

JuanC

Link to comment
Share on other sites

  • 4 weeks later...

Hi

 So given my code snippet above, is it possible to use that code (or, should it be possible) to serialize a chart to XML?  If not, can you provide a sample that works?  We require a complete serialization, including data (we don't use styles for the bar / line visuals).

Your post hints that serialization is not currently 100% working - is this the case?

Many thanks

 

Paul

Link to comment
Share on other sites

We do not support XmlSerializer as a way to persist a chart.

If you use our Export/Import API we will persist all the settings except for data or user-supplied data templates.

If you use the Clone API (that returns a cloned chart) we will persist all chart attributes including data.

JuanC

Link to comment
Share on other sites

Thanks for the update - can you confirm if your control would be compatible if used in conjunction with the XamlWriter and XamlReader?  We use your control in conjunction with another, which is the one firing the serialization routines.

With reference to the Clone API, you say that it returns a cloned chart.  This sounds a lot like it is just duplicating an object to create another rather then a serialization of the object to something like XML for persistance outside of the application - is this assumption correct?

 

Many thanks

 

Paul

Link to comment
Share on other sites

  • 2 weeks later...

We have been working on supporting XamlWriter/XamlReader as a serialization method, most of this code is also used when VS/Blend save to XAML so we have been doing it on a separate branch.

You are probably already aware of this, but there are some limitations involved in serializing to XAML

1) Your data should be serializable, this means you need empty constructors, setters for your properties, etc. Note that sometimes if you have deep graphs serializing your data as XAML might get long. A quick way to test this would be to create a listbox passing the same data you are passing to the chart and using XamlWriter/XamlReader to persist into a new listbox

2) XamlWriter does not retain markup extensions so Bindings are lost. This can be quickly tested by repeating the same listbox experiment but setting ListBox.ItemTemplate with a DataTemplate that contains a binding. e.g. <DataTemplate><TextBlock Text="{Binding Path=FirstName}"/></DataTemplate>

This is documented officially here and also on this blog.

3) XamlWriter will not recreate static references (same reason as before), because of this if you use ChartFX.WPF.Motifs.Basic.Style as the chart's style this will result in

- The XAML will be pretty big, some of our styles include resource dictionaries that control how are galleries are painted (both 2D and 3D) as well as several control templates and data templates, all of this will be dumped in your XAML.

- If you are using this XAML as a persistent method of serialization (e.g. you are saving this in a database) you will be saving a snapshow of what our style looked at the time you save it, if we fix issues in our style those changes will not be used when recreating a chart from the XAML. Sometimes this might be a good thing but some others it will not.

We are considering adding a flag to the chart so that a runtime we can ignore the properties that cause the XAML to grow too big and the same time keep these statics as references instead of copies. Your feedback on this would be appreciated.

Please drop a message to wpf at softwarefx dot com referencing this thread and we will provide a set of bits where we try to support XamlWriter, we have tested some charts but certainly not all properties or combination of properties so some of our more complex settings might not get saved. Also please let us know if this affects the ChartFX behavior inside VS or Blend.

Regards,

JuanC

Link to comment
Share on other sites

  • 1 month later...

Hi 

Need to dredge this one up again - sorry :) 

Do you have any update as to your XAMLWriter work?  I tried serializing with the latest dlls but got:

"Could not load file or assembly 'PresentationFramework' or one of its dependencies. The system cannot find the file specified."

during compiling.  Serialization is a pretty fundamental thing for us; while performance is less of an issue at present as things can be tuned later, without the functionality we have an issue.

 

Thanks

 

Paul

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...