Crainiate Community

Support and discussion for users of Crainiate component software products
Welcome to Crainiate Community Sign in | Join | Help
in Search

Diagram class failed to Load file.

Last post 03-08-2009 8:38 PM by James Westgate. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 07-27-2007 10:30 AM

    Diagram class failed to Load file.

    Hi , I need a read only diagram. So I use a Diagram class to load a file ,which was saved by a Model class.

    The Model class load the file succeed  . There was no lucky with the Diagram class .

    The error was

    "The type Crainiate.ERM4.Model in Assembly Crainiate.ERM4, Version=4.1.2665.32214, Culture=neutral, PublicKeyToken=df8e50c7fad67e61 is not marked as serializable. "

    Do I miss something ?  

     

    • 218.170.230.122
  • 07-30-2007 9:15 PM In reply to

    Re: Diagram class failed to Load file.

    The Model and Diagram class uses serialization surrogate classes named DiagramSerialize and ModelSerialize that implement ISerializationSurrogate. These classes handle the serialization of diagram classes together with the DiagramBinder class.

     Please let us know if you need further help with this.

    • 86.155.94.155
  • 07-31-2007 8:38 AM In reply to

    Re: Diagram class failed to Load file.

     Sorry, I don't understand.

     What I do is very simple.

    Just copy code from Help

    something like.. 

    //Create a shape and add to the model
    Shape shape = new Shape();
    shape.Location = new PointF(100,100);
    shape.DrawGradient = true;
    shape.GradientColor = Color.PaleGoldenrod;
    shape.Opacity = 80;
    model1.Shapes.Add("shape1",shape);

    //Create another shape and use previous shape as a prototype
    Shape shape2 = new Shape(shape);
    shape2.Location = new PointF(200,200);
    model1.Shapes.Add("shape2",shape2);

     and

            private void button1_Click(object sender, EventArgs e)
            {
                model1.Save(@"c:\ssc.xml");
            }

     

            private void button2_Click(object sender, EventArgs e)
            {
                diagram1.Open(@"c:\ssc.xml");///  I got error here..
            }
     

     I don't know what's wrong with it. Thanks for your help.

     
     

    • 218.170.230.122
  • 08-03-2007 10:00 AM In reply to

    Re: Diagram class failed to Load file.

    The problem is that the diagram does not know how to deserialize the extra information in the file. You can solve this by telling it which class is responsible for deserializing this information.

    1. Make sure you are using some appropriate namespaces

    using System.Runtime.Serialization;
    using
    Crainiate.ERM4;
    using Crainiate.ERM4.Serialization;

    2. Handle the deserialize event and add a ModelSerialize object to deserialize the extra model data

    private void button5_Click(object sender, EventArgs e)
    {
        model1.Open(
    "test.xml", LoadFormat
    .Xml);

        diagram1.Deserialize +=
    new SerializeEventHandler(diagram1_Deserialize);

        diagram1.Open(
    "test.xml", LoadFormat.Xml);
    }

    private void diagram1_Deserialize(object sender, SerializationEventArgs e)
    {
       
    ModelSerialize surrogate = new ModelSerialize
    ();

        e.Selector.AddSurrogate(typeof(Model), new StreamingContext(StreamingContextStates.All), surrogate);
    }

    • 86.155.94.155
  • 03-03-2009 8:40 PM In reply to

    Re: Diagram class failed to Load file.

    I have a similar problem, but slightly different.  When I use the Crainiate class Model in my form, it works fine:

    private void InitializeComponent()
    {
        this.theModel = new Crainiate.ERM4.Model();
    }

    private void buttonTest_Click(object sender, EventArgs e)
    {
        try
        {
            MemoryStream theStream = new MemoryStream();
            theStream.Seek(0, SeekOrigin.Begin);
            theModel.Save(theStream, SaveFormat.Binary);
            theStream.Seek(0, SeekOrigin.Begin);
            theModel.Open(theStream, LoadFormat.Binary);
        }
        catch (Exception exception)
        {
            MessageBox.Show(exception.ToString());
        }
    }

    If I press buttonTest, it works fine without any problems.

    Now if I make a derived model class to override some protected methods like this:

    public class MyModel : Model
    {
        protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
        {
            if (keyData == System.Windows.Forms.Keys.Delete)
            {
                // Do something here.
                return true;
            }
            else
            {
                 return base.ProcessCmdKey(ref msg, keyData);
            }
        }
    }

    And I change my form to instantiate this derived class:
    private void InitializeComponent()
    {
        this.theModel = new MyModel() as Crainiate.ERM4.Model;
    }

    Now if I call buttonTest, I get an exception on the Save method:
    exception = {"Type '..MyModel' in Assembly 'MyAssembly, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable."}

     

    Now if I mark my model class with the [Serializable] attribute, then the exception I get on Save is :
    exception = {"Type 'Crainiate.ERM4.Model' in Assembly 'Crainiate.ERM4, Version=4.1.2665.32214, Culture=neutral, PublicKeyToken=df8e50c7fad67e61' is not marked as serializable."}

    What do I need to do with my derived model to get it to serialize and deserialize?

     

    Thanks,
    Jim

    • 216.123.208.30
  • 03-08-2009 8:38 PM In reply to

    Re: Diagram class failed to Load file.

    Try adding the ModelSerialize class as a surrogate as in the example above for the myModel class
    • 86.130.66.27
Page 1 of 1 (6 items)