Error Pasting GoSubGraph

Hi,
I’m getting a strange error and I have no idea how to resolve it. I have some subs that override the EditPaste() and the EditCopy() in my GoView class. When I copy a GoSubGraph that contains a link the MyBase.EditCopy (MyBase being the GoView) executes perfectly without any errors. But then when I try to paste the GoSubGraph using MyBase.EditPaste I get an error that says:
“System.NullReferenceException: Object reference not set to an instance of an object.at Northwoods.Go.GoView.EditPaste()”
And the only thing I can make out is the Link.FromNode and the Link.ToNode properties are set to nothing.
Since I am getting this error before I do any of the code I have added to the EditPaste sub, I am at a loss how to test this problem and resolve it. Can you provide me with some ideas of how to test and figure out this problem??
Thanks!
Joy

You could test whether those objects are properly serialized by doing it yourself, writing and reading a file: Dim ofile As Stream = File.Open("test.graph", FileMode.Create) Dim oformatter As IFormatter = new BinaryFormatter() oformatter.Serialize(ofile, myView.Document) ofile.Close() and: Dim ifile As Stream = File.Open("test.graph", FileMode.Open) Dim iformatter As IFormatter = new BinaryFormatter() Dim doc As GoDocument = CType(iformatter.Deserialize(ifile), GoDocument) ifile.Close() myView.Document = doc [Sorry if I have translated this into VB incorrectly]

When I do as you suggest, I get the following error:
An unhandled exception of type ‘System.Runtime.Serialization.SerializationException’ occurred in system.windows.forms.dll
Additional information: The type Csu.Modsim.ModsimModel.Model in Assembly libsim, Version=1.0.1745.17363, Culture=neutral, PublicKeyToken=null is not marked as serializable.
It blows up when I try to Serialize the GoDocument:
oformatter.Serialize(ofile, MyBase.Document)
So I think I can safely conclude it’s not being serialized correctly, any ideas on what is causing this??
I think the main problem is with links, I am able to copy and paste subgraphs that only contain nodes just fine.
Joy

As the error message states, I think you haven’t marked that class as <Serializable()>, and made sure every field is either serializable or marked as <NonSerialized()>.

My node, link, and subgraph classes are all marked Serializable

Please read that error message carefully. Is that class marked <Serializable()>?

yes my node, link and subgraph classes are ALL marked <Serializable()>
I can successfully copy and paste nodes and links NOT contained in a GoSubGraph, I can successfully paste a GoSubGraph only containing nodes, THE ONLY time it breaks is when I try to copy and paste a subgraph containing a link.
If I use a Try, Catch statement to catch the error and proceede to loop through all the objects contained in the GoSubGraph, everything looks fine but the link’s FromNode and ToNode properties are set to nothing.

I am having this same problem with the Demo1 example provided by GoDiagram. When I open up Demo1 and drag and drop the “outer” subgraph from the Palette, go to the Edit Menu and select “Copy” - I immediately get an “unhandled exception.”
So if you could give that a try and see if you get the same results as me I would really appreciate it.
Joy

Hmm. It worked fine for me. I’m running the Demo1.exe that comes with the 2.2.2 kit. Have you modified and recompiled the Demo1 sample?

I did some more testing on it and it turns out that GoDiagram copy/paste functionality doesn’t work while VNC Server is on. I guess VNC takes control of the clipboard or something - so that was why the Demo1 didn’t work I believe. Unfortunately that didn’t fix the problem with my actual application. I am still getting the same error but strangely enough, I am able to Serialize and Deserialize the subgraph manually now without any problems. So I’m not sure what the problem is.
So now I am stepping through all my OnLayerChanged subs for my SubGraphs, Links and Nodes - hopefully I will come across something there - but if you have any advice for me I would greatly appreciate it!
Thanks!
Joy

Are you still getting the NullReferenceException?

Yes I am, I am getting this error:
System.NullReferenceException: Object reference not set to an instance of an object.
when I attempt to execute the following code in the Overrides OnLayerChanged Sub of my inherited GoNode class :
Me.Label.Text = s (Me refers to one of the nodes contained in the subgraph and s is the unique name for the node)
And I can’t for the life of me figure out why it is blowing up here - any ideas?
Joy

Presumably there’s no Label for your node at that time.
Under what circumstances are you executing that statement in your override of OnLayerChanged?

Here is the complete code:
Protected Overrides Sub OnLayerChanged(ByVal oldlayer As GoLayer, ByVal newlayer As GoLayer, ByVal mainObject As GoObject)
MyBase.OnLayerChanged(oldlayer, newlayer, mainObject)
If oldlayer Is Nothing AndAlso Not newlayer Is Nothing AndAlso TypeOf newlayer.Document Is NetworkDocument Then
Dim doc As NetworkDocument = CType(newlayer.Document, NetworkDocument)
Dim s As String
'Make sure the name is unique, ignoring this node itself
s = MakeUniqueName(Me.Text)
Me.Label.Text = s
End If
End Sub

Also, when I stop the code right before it tries to execute the line:
Me.Label.Text = s
And I check to see if “Me” is set to a GoNode and “Label” is set to a GoLabel, they are. Neither of them are set to nothing, and it executes the statement and changes the text of label but it also produces an exception. It’s like another function is running after that point and is producing the error, but I have no idea what that function might be, that’s what I am trying to track down right now - any ideas?

You need to look at the stack at the point of the exception. Chances are there’s some code running in a GoDocument.Changed event handler that is noticing the ChangedText change to a GoText object.

ok - I am starting to panic - drag and drop operations for my GoNodes from a GoPalette to a GoDocument is no longer working - it worked yesterday but it doesn’t work today - and I have not only made no changes to the drag drop functions but I haven’t made any changes to the code at all anywhere. Why is this happening!!

It appears that GoDiagram doesn’t support the copying and pasting of subgraphs only when additional code attempts to ensure the nodes and links contained in the subgraphs have unique names in the GoDiagram document. The following code works perfectly except when a subgraph and it’s corresponding nodes and links are being copied and pasted - then it generates a System.NullReferenceException.
Protected Overrides Sub OnLayerChanged(ByVal oldlayer As GoLayer, ByVal newlayer As GoLayer, ByVal mainObject As GoObject)
MyBase.OnLayerChanged(oldlayer, newlayer, mainObject)
If oldlayer Is Nothing AndAlso Not newlayer Is Nothing AndAlso TypeOf newlayer.Document Is NetworkDocument Then
Dim doc As NetworkDocument = CType(newlayer.Document, NetworkDocument)
'Make sure the name is unique, ignoring this node itself
Me.Text = MakeUniqueName(Me.Text)
End If
End Sub
It appears the only “fix” for this problem is to not allow the copying and pasting of subgraphs. However, another solution would be greatly appreciated since this is a needed functionality for our user interface.
Thanks!
Joy


What does MakeUniqueName do? What statement causes the exception?

MakeUniqueName ensures that the current node name is unique in the GoDiagram network - and if it’s not unique, MakeUniqueName makes the name unique. In this function I not only loop through all the objects contained in the document, but I also loop through all the nodes contained in the subgraphs to ensure the name is unique. This line of code blows up on ONLY when I am trying to copy and paste a subgraph containing nodes and links is:
If not n is ME then
In this instance n is a node contained in a subgraph.
My theory is that GoDiagram is not able to handle the changing of names for nodes contained in subgraphs until a specific point in the copy and paste process. But I have no idea when that point might be.
Joy