System.ArgumentException on ILayoutAlgorithm

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

Hello,

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 
'GraphSharp.Algorithms.Layout.ILayoutAlgorithm`3[TVertex,TEdge,
TGraph]' violates the constraint of type 'TEdge'.

Window xaml:

 

<Window x:Class="AtmSim.TopologyView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:graphsharp="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
        xmlns:zoom="clr-namespace:WPFExtensions.Controls;assembly=WPFExtensions"
        Title="Topologia sieci" Height="400" Width="400"
        x:Name="Topology">
    <Grid>
        <zoom:ZoomControl>
            <graphsharp:GraphLayout x:Name="graphLayout"
                                    Graph="{Binding ElementName=Topology, Path=Graph}"
                                    LayoutAlgorithmType="FR"
                                    OverlapRemovalAlgorithmType="FSA"
                                    HighlightAlgorithmType="Simple" />
           
            
        </zoom:ZoomControl>
    </Grid>
</Window>

 

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.AddVertex("A");
            g.AddVertex("B");
            g.AddVertex("C");
            g.AddEdge(new Edge<object>("A", "B"));
            g.AddEdge(new Edge<object>("A", "C"));
            g.AddEdge(new Edge<object>("B", "C"));
            this._Graph = g;
            InitializeComponent();
        }
    }
}

 

Opening the window:

 

TopologyView topologyView = new TopologyView();
topologyView.Show();

 

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

mynamespace:MyGraphLayout

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...
David
Jul 25, 2011 at 8:01 AM

Hi. Has this been resolved?

I have encountered the same error and posted it, http://graphsharp.codeplex.com/discussions/264403 .

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