I am having trouble loading a diagram with some custom labels added to the symbols. The project is based on the sample DiagramBuilder project. I have implemented a number of wrapper classes:
PEPDiagram : Diagram
PEPModel : Model
PEPSymbolLabel : SymbolModel
I believe I have implemented the necessary methods for serialization of the new properties added to the classes. I can save and load a diagram when my symbols DO NOT contain PEPSymbolLabels. However, when I add a PEPSymbolLabel I CAN save it, but when I attempt to open the save diagram I get an error:
Serialization error - Exception has been thrown by the target of an invocation.
I then get an exception:
An unhandled exception of type ''System.NullReferenceException'' occurred in DiagramBuilder.exe
Additional information: Object reference not set to an instance of an object.
When I step through the code, the serialization is attempting to set the value of the PEPSymbolLabel.ReadOnly property, it is at this point that the exception is raised.
It is almost as if there is no instance of PEPSymbolLabel before it attempts to set the property.
I have attached my source code. Any help would be much appreciated.
Am newbie to C# so I suspect that I am doing something daft!
Thanks for you quick response in previous posts.
Further to my post I have been working on this issue. I seem to have come upon a work around, although I still suspect that it is something I am doing.
In my LabelType set routine I am setting such properties as ReadOnly, Anchor etc... which I use when I create the SymbolLabel. However, these are being called during serialization and subsequently cannot be set, as I assume the object has not been instantiated at that time? My work around is to set a flag in the serialization constructor:
protected PEPSymbolLabel(SerializationInfo info, StreamingContext context) : base(info, context)
boolDeserialising = true;
LabelType = (LabelTypes) info.GetUInt16
boolDeserialising = false;
Now when the LabelType set routine is called I check if bool Deserializing is True and do not set the properties.
Is there a more generic way of doing this, or even a best practice when using my set routine?
ADAdministrator Syncfusion Team September 23, 2004 11:13 AM
I tried running the sample and I could not reproduce the problem. Can you post a stripped down version (without the splash screen, to save some time :-)) along with steps to reproduce the problem.
Also, can you take a look at the sample I posted in this forms post which demonstrates how a Custom Symbol can be serialized as this is what you are trying to do.
Thanks for your cooperation and continued support for Syncfusion.
JBJames BrockSeptember 24, 2004 03:05 AM
Am getting on better now and have looked at your example.
Don''t suppose you can remove the source zip from my original post could you? Thought I had posted a version without the splash, but obviously not!
ADAdministrator Syncfusion Team September 24, 2004 04:35 AM
Thanks for the update. Kindly update this posting if you have any further questions.