TargetInvocationException in mscorlib.dll on changing graph

Oct 17, 2012 at 4:51 AM
Edited Oct 17, 2012 at 6:26 AM

First - great thanks to the devs of graphsharp! It's an awesome library and very easy to use.

However I ran into the following problem. After removing vertices and edges from the graph model and adding new ones, the library seems to randomly throw TargetInvocationException. This occurs during layout update animation, after a graph has been changed. Here is the stack trace:

WindowsBase.dll!System.Windows.DependencyObject.InvalidateProperty(System.Windows.DependencyProperty dp, bool preserveCurrentValue)mscorlib.dll!System.Delegate.DynamicInvokeImpl(object[] args)PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeEventHandler(System.Delegate genericHandler, object genericTarget)PresentationCore.dll!System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate handler, object target)PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs)PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source, System.Windows.RoutedEventArgs args, bool reRaised)PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args)PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs e)GraphSharp.Controls.dll!GraphSharp.Controls.GraphElementBehaviour.HighlightTrigger_Coerce(System.Windows.DependencyObject d, object baseValue)WindowsBase.dll!System.Windows.DependencyObject.ProcessCoerceValue(System.Windows.DependencyProperty dp, System.Windows.PropertyMetadata metadata, ref System.Windows.EntryIndex entryIndex, ref int targetIndex, ref System.Windows.EffectiveValueEntry newEntry, ref System.Windows.EffectiveValueEntry oldEntry, ref object oldValue, object baseValue, object controlValue, System.Windows.CoerceValueCallback coerceValueCallback, bool coerceWithDeferredReference, bool coerceWithCurrentValue, bool skipBaseValueChecks)WindowsBase.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex entryIndex, System.Windows.DependencyProperty dp, System.Windows.PropertyMetadata metadata, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType)PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.Invalidate(bool isASubPropertyChange)PresentationFramework.dll!System.Windows.Data.BindingExpression.TransferValue(object newValue, bool isASubPropertyChange)PresentationFramework.dll!System.Windows.Data.BindingExpression.ScheduleTransfer(bool isASubPropertyChange)PresentationFramework.dll!MS.Internal.Data.ClrBindingWorker.NewValueAvailable(bool dependencySourcesChanged, bool initialValue, bool isASubPropertyChange)PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(int k, System.ComponentModel.ICollectionView collectionView, object newValue, bool isASubPropertyChange)PresentationFramework.dll!MS.Internal.Data.PropertyPathWorker.OnDependencyPropertyChanged(System.Windows.DependencyObject d, System.Windows.DependencyProperty dp, bool isASubPropertyChange)PresentationFramework.dll!MS.Internal.Data.ClrBindingWorker.OnSourceInvalidation(System.Windows.DependencyObject d, System.Windows.DependencyProperty dp, bool isASubPropertyChange)PresentationFramework.dll!System.Windows.Data.BindingExpression.HandlePropertyInvalidation(System.Windows.DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs args)PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.OnPropertyInvalidation(System.Windows.DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs args)PresentationFramework.dll!System.Windows.Data.BindingExpression.OnPropertyInvalidation(System.Windows.DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs args)WindowsBase.dll!System.Windows.DependentList.InvalidateDependents(System.Windows.DependencyObject source, System.Windows.DependencyPropertyChangedEventArgs sourceArgs)WindowsBase.dll!System.Windows.DependencyObject.NotifyPropertyChange(System.Windows.DependencyPropertyChangedEventArgs args)WindowsBase.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex entryIndex, System.Windows.DependencyProperty dp, System.Windows.PropertyMetadata metadata, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType)WindowsBase.dll!System.Windows.DependencyObject.SetValueCommon(System.Windows.DependencyProperty dp, object value, System.Windows.PropertyMetadata metadata, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType, bool isInternal)WindowsBase.dll!System.Windows.DependencyObject.SetValue(System.Windows.DependencyPropertyKey key, object value)WindowsBase.dll!System.Windows.DependencyObject.SetValue(System.Windows.DependencyPropertyKey dp, bool value)PresentationCore.dll!System.Windows.ReverseInheritProperty.FirePropertyChangeInAncestry(System.Windows.DependencyObject element, bool oldValue, MS.Internal.DeferredElementTreeState treeState, System.Action<System.Windows.DependencyObject,bool> originChangedAction)PresentationCore.dll!System.Windows.ReverseInheritProperty.FirePropertyChangeInAncestry(System.Windows.DependencyObject element, bool oldValue, MS.Internal.DeferredElementTreeState treeState, System.Action<System.Windows.DependencyObject,bool> originChangedAction)PresentationCore.dll!System.Windows.ReverseInheritProperty.FirePropertyChangeInAncestry(System.Windows.DependencyObject element, bool oldValue, MS.Internal.DeferredElementTreeState treeState, System.Action<System.Windows.DependencyObject,bool> originChangedAction)PresentationCore.dll!System.Windows.ReverseInheritProperty.FirePropertyChangeInAncestry(System.Windows.DependencyObject element, bool oldValue, MS.Internal.DeferredElementTreeState treeState, System.Action<System.Windows.DependencyObject,bool> originChangedAction)PresentationCore.dll!System.Windows.ReverseInheritProperty.FirePropertyChangeInAncestry(System.Windows.DependencyObject element, bool oldValue, MS.Internal.DeferredElementTreeState treeState, System.Action<System.Windows.DependencyObject,bool> originChangedAction)PresentationCore.dll!System.Windows.ReverseInheritProperty.OnOriginValueChanged(System.Windows.DependencyObject oldOrigin, System.Windows.DependencyObject newOrigin, System.Collections.Generic.IList<System.Windows.DependencyObject> otherOrigins, ref MS.Internal.DeferredElementTreeState oldTreeState, System.Action<System.Windows.DependencyObject,bool> originChangedAction)PresentationCore.dll!System.Windows.Input.MouseDevice.ChangeMouseOver(System.Windows.IInputElement mouseOver, int timestamp)PresentationCore.dll!System.Windows.Input.MouseDevice.PreNotifyInput(object sender, System.Windows.Input.NotifyInputEventArgs e)PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea()PresentationCore.dll!System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs input)PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport inputReport)PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.ReportInput(System.IntPtr hwnd, System.Windows.Input.InputMode mode, int timestamp, System.Windows.Input.RawMouseActions actions, int x, int y, int wheel)PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.FilterMessage(System.IntPtr hwnd, MS.Internal.Interop.WindowMessage msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)PresentationCore.dll!System.Windows.Interop.HwndSource.InputFilterMessage(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o)WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)WindowsBase.dll!MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(object source, System.Delegate method, object args, int numArgs, System.Delegate catchHandler)WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs)WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam)[Native to Managed Transition][Managed to Native Transition]WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame)WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame)WindowsBase.dll!System.Windows.Threading.Dispatcher.Run()PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore)PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window)PresentationFramework.dll!System.Windows.Application.Run(System.Windows.Window window)PresentationFramework.dll!System.Windows.Application.Run()FlowAnalyzer.exe!FlowAnalyzer.App.Main()[Native to Managed Transition][Managed to Native Transition]mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args)Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state)mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)mscorlib.dll!System.Threading.ThreadHelper.ThreadStart()[Native to Managed Transition] 

Essentially what I have is a directed graph, representing a flow, where certain nodes represent sub-flows. If the user clicks on a node, it is removed from the graph and replaced with a list of subflow vertices and edges that it represents. This is loaded from XML. Here's a simplified version of the code that I run upon clicking the node:

 

public void LoadSubflow(PocVertex v)
{
       XElement subflow = Utilities.getSubFlowNode(v.Element);

       PocVertex start = AddVertices(subflow);

       AddEdges(v, start);

       Graph.RemoveVertex(v);

}

private PocVertex AddVertices(XElement flow)
{
       PocVertex startnode = null;
       IEnumerable<XElement> children = flow.Elements();
       foreach (XElement child in children)
       {
            PocVertex v = new PocVertex(child);
            Graph.AddVertex(v);
            if (Utilities.getNodeName(child) == "START")
            {
                startnode = v;
            }
        return startnode;
}

private void AddEdges(PocVertex replaced, PocVertex start)
{
     foreach (PocEdge edge in replaced.IncomingEdges)
     {
          PocEdge newEdge = new PocEdge(edge.Source, start);
          edge.Source.OutgoingEdges.Add(newEdge);
          start.IncomingEdges.Add(newEdge);
          Graph.AddEdge(newEdge);
     }
}

EDIT: I found that if I disable the highlight algorithm, no more exceptions are being thrown. I would however like to use the highlight feature.

Any help or information about the exception would be greatly appreciated! Thanks!