System.ArgumentException on ILayoutAlgorithm

Dec 6, 2010 at 10:43 AM
Edited Dec 6, 2010 at 10:46 AM


I wanted to use Graph# to draw a network topology in my application. I wrote a standalone WPF Application, viewed the graph and it works. Then I copied the window class code and xaml into my project, and I get an error:

System.ArgumentException was thrown on TopologyView.xaml":
GenericArguments[1], 'QuickGraph.IEdge`1[System.Object]', on 
TGraph]' violates the constraint of type 'TEdge'.

Window xaml:


<Window x:Class="AtmSim.TopologyView"
        Title="Topologia sieci" Height="400" Width="400"
            <graphsharp:GraphLayout x:Name="graphLayout"
                                    Graph="{Binding ElementName=Topology, Path=Graph}"
                                    HighlightAlgorithmType="Simple" />


Window code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using QuickGraph;

namespace AtmSim
    /// <summary>
    /// Interaction logic for TopologyView.xaml
    /// </summary>
    public partial class TopologyView : Window
        private IBidirectionalGraph<object, IEdge<object>> _Graph;
        public IBidirectionalGraph<object, IEdge<object>> Graph
            get { return _Graph; }

        public TopologyView()
            var g = new BidirectionalGraph<object, IEdge<object>>();
            g.AddEdge(new Edge<object>("A", "B"));
            g.AddEdge(new Edge<object>("A", "C"));
            g.AddEdge(new Edge<object>("B", "C"));
            this._Graph = g;


Opening the window:


TopologyView topologyView = new TopologyView();


When I open the TopologyView window, the graph is drawn, I see vertices being relocated by the layout algorithm, but after less than a second, the program freezes and the exception is thrown.

I don't get any errors when I comment out the GraphLayout in xaml and I can freely insert any other control (from toolbox).

Also, when I typed the xaml code into the TopologyView window, Visual Studio showed the error right after typing "<graphsharp:GraphLayout".

Of course I have references to GraphSharp, GraphSharp.Controls, QuickGraph and WPFExtensions in my project.

Thanks in advance.

Dec 8, 2010 at 1:29 PM

shot in the dark...

graphsharp:GraphLayout should be replaced with something like


where the following exists in mynamespace

 public class MyGraphLayout : GraphLayout<AVertexAEdgeAGraph> { }

defined in one of your class

where Avertex, Aedge & Agraph are classes you've written (or use the ones provided in the samples) in which they are called PoCVertex ... Poc...
Jul 25, 2011 at 8:01 AM

Hi. Has this been resolved?

I have encountered the same error and posted it, .

I am trying to understand the solution that was posted by GreyCloud.