0

i need to to some work with Edge object before adding it to graph, so i create it like this

private void AddNewEdgeToGraph(string sourceNodeID, string targetNodeID)
    {
        Edge newEdge = new Edge(sourceNodeID, "", targetNodeID);
        newEdge.LabelText = newEdge.Attr.Weight.ToString();
        graph.AddPrecalculatedEdge(newEdge);
    }

And, as you have guessed, i get the NullReferenceException on the last line of code. I doubleChecked the parameters for correctness, and i am sure the graph contains nodes with such IDs. I have also tried to add Edges this way:

Edge newEdge = new Edge(graph.FindNode("path1"), graph.FindNode("path2"), 
     ConnectionToGraph.Connected);
newEdge.LabelText = newEdge.Attr.Weight.ToString();
graph.AddPrecalculatedEdge(newEdge);

And this one works correctly. I thought that the first variant uses the second underneath the hood, so what may be the problem?

TheSmokingGnu
  • 302
  • 2
  • 6
  • 15
  • Speculating, but I think the `ConnectionToGraph.Connected` has to do with initializing the `Edge` type for proper usage. – Svek Jun 03 '17 at 16:59
  • See marked duplicate for extensive advice regarding diagnosis and resolution of `NullReferenceException` problems. If you are unable to solve your problem with that information, post a new question in which you take the time to provide a good [mcve] that reliably reproduces the problem, and a detailed, precise explanation of what debugging you've done so far, and what _specifically_ you are having trouble figuring out. – Peter Duniho Jun 03 '17 at 23:00

0 Answers0