FubarDevelopment / QuickGraph

Fork of https://quickgraph.codeplex.com/
Microsoft Public License
9 stars 2 forks source link

CP-18986: GraphML Serialization in Silverlight Runtime Error #106

Open fubar-coder opened 6 years ago

fubar-coder commented 6 years ago

From unknown CodePlex user on Thursday, 21 October 2010 22:24:27

QuickGraph is bad ass! I may have found an error though... Anything thoughts are would be greatly appreciated Thanks!     The following code and XML works perfectly in .NET 4 but fails in Silverlight 4. The code will compile in SL4, but silently fails during run time.   <?xml version="1.0" encoding="utf-16"?>

  private string GraphToXml(FlockGraph graph) { StringBuilder sb = new StringBuilder();   using (XmlWriter writer = XmlWriter.Create(sb)) { var serializer = new GraphMLSerializer<FlockVertex, FlockEdge, FlockGraph>(); serializer.Serialize(writer, graph, v => v.ID, e => e.ID); writer.Flush(); }   return sb.ToString(); }   private FlockGraph XmlToGraph(string XmlGraph) { FlockGraph graph = new FlockGraph();   using (XmlReader reader = XmlReader.Create(new StringReader(XmlGraph))) { var serializer = new GraphMLDeserializer<FlockVertex, FlockEdge, FlockGraph>();   serializer.Deserialize(reader, graph, id => new FlockVertex(id), (source, target, id) => new FlockEdge(source, target)); }   return graph; }

fubar-coder commented 6 years ago

Form unknown CodePlex user on Sunday, 07 November 2010 05:08:18

ouch the serializer uses features that are not supported on sl.

fubar-coder commented 6 years ago

Form unknown CodePlex user on Monday, 08 November 2010 03:05:06

I ended up writing a quick and dirty custom deserializer. I found one major difference in how SL differs from .NET as far XML; in SL you have to explicitly say “MoveToElement” when reading element content. In .NET you can just write GetConent or whatever the .NET method is called. ... reader.MoveToElement(); XmlReader inner = reader.ReadSubtree(); while (inner.Read()) { if (inner.Name == "data") //Custom Attributes { if (inner.HasAttributes) { while (inner.MoveToNextAttribute()) { if (inner.Name == "key") { if (inner.Value == "Name") { inner.MoveToElement(); // <<<---- Explicitly Move Reader In SL name = inner.ReadElementContentAsString(); } ...

pelikhan, I saw that you where working on the BronKerboshMaximumCliqueAlgorithm class, do you have a ball park ETA on that?