Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic "Index was out of range" exception is thrown when a diagram saved in WinForms opens in WPF. (Read 3194 times)
Homam
Junior Member
**
Offline


I Love MindFusion!

Posts: 67
Joined: Feb 7th, 2012
"Index was out of range" exception is thrown when a diagram saved in WinForms opens in WPF.
Oct 22nd, 2012 at 12:36pm
Print Post  
I'm having the following exception when I open a diagram in a WPF application saved through a Windows Forms Application.

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
   at System.Collections.CollectionBase.System.Collections.IList.get_Item(Int32 index)
   at MindFusion.Utilities.DistToBezier(Point pt, IList bez_pts, Int32 nPoints)
   at MindFusion.Diagramming.Wpf.DiagramLink.ContainsPoint(Point point)
   at MindFusion.Diagramming.Wpf.Diagram.JP(Point A, Boolean B)
   at MindFusion.Diagramming.Wpf.Diagram.GetItemAt(Point pt, Boolean exclLocked)
   at MindFusion.Diagramming.Wpf.Diagram.HN(Point A)
   at MindFusion.Diagramming.Wpf.Diagram.XN(Point A)
   at MindFusion.Diagramming.Wpf.Diagram.OnPreviewMouseMove(MouseEventArgs e)
   at System.Windows.UIElement.OnPreviewMouseMoveThunk(Object sender, MouseEventArgs e)
   at System.Windows.Input.MouseEventArgs.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.StartDispatcherInBrowser(Object unused)
   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.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(
TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(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)


This exception is thrown only when I move the mouse over the undrown link.


Please check the attached image
  

001_diagram.png (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: "Index was out of range" exception is thrown when a diagram saved in WinForms opens in WPF.
Reply #1 - Oct 22nd, 2012 at 2:05pm
Print Post  
Are you using version 6 of the WinForms control? Current WpfDiagram version cannot read its file format correctly yet. We are starting beta tests of WpfDiagram V3 later this week, and it should be able to load latest file format of Windows Forms control.
  
Back to top
 
IP Logged
 
Homam
Junior Member
**
Offline


I Love MindFusion!

Posts: 67
Joined: Feb 7th, 2012
Re: "Index was out of range" exception is thrown when a diagram saved in WinForms opens in WPF.
Reply #2 - Oct 23rd, 2012 at 6:26am
Print Post  
Yes. I'm using Windows Form v. 6.0.0.25096 and WPF v. 2.8.2.15403. These were the latest on your website. I downloaded them both together.

Another question.. Is the exception caused because the compatibility problem?

Finally.. What I'm supposed to do? I cannot wait more than few days. Any suggestion?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: "Index was out of range" exception is thrown when a diagram saved in WinForms opens in WPF.
Reply #3 - Oct 23rd, 2012 at 6:45am
Print Post  
Yes, it's a compatibility problem after Flowchart.NET 6 added a DiagramItem.Style property, and we had to rename DiagramLink.Style to DiagramLink.Shape. Now the WpfDiagram's LoadFromXml method will try to load links' Shape property from a "Style" element in the XML, while Flowchart.NET 6 writes its values in a "Shape" element. Not finding it, the links are loaded with default Bezier shape, not corresponding to the number of loaded points and causing an exception.

So you could work around that by changing element names in the XML file from Shape to Style before loading, or fixing links' Shape and ControlPoints after loading:

Code
Select All
if (link.Shape == Bezier && link.ControlPoints.Count = 2) {
    link.Shape = Polyline;
    link.SegmentCount = 1;
} 



Otherwise, if you are a client, you could download FlowChart.NET 5.8 from http://clientsarea.eu/ to have compatible XML versions. You might also request our latest WpfDiagram V3 build from support@mindfusion.eu, but I don't know how stable it is at this time - you'd have to check if the features you are using work ok.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint