Menu

#193 C# Serialization seems to fail

Assigned
closed-fixed
None
5
2015-02-15
2014-02-25
DipSwitch
No

Hello,

Great software, but it seems like I'm having trouble with serializing and deserializing the the current state and restoring it.
It seems that the State it self is not serialized. I followed the example from the manual and implemented this on the C sharp example EX1:

The first cycle I use the create state machine, the second cycle is after serialization and deserialization.

I included the test project with this post.

Another thing is that the AppClassContext which is generated by the SMC isn't marked [Serializable]

state processing after initializationThe string "1Z010E111" is not acceptable.
state processing after serialize/deserializeThe string "1Z010E111" is

Exception: statemap.StateUndefinedException
--------------------------------------------------------------------
statemap.StateUndefinedException: Error in the application.
   at AppClassContext.get_State() in d:\EX1\AppClass1.cs:line 22
   at AppClassContext.EnterStartState() in d:\EX1\AppClass1.cs:line 62
   at AppClass.CheckString(String inputString) in d:\EX1\AppClass.cs:line 74
   at checkstring.Main(String[] args) in d:\EX1\checkstring.cs:line 74
press any key to continue...
1 Attachments

Discussion

  • Charles Rapp

    Charles Rapp - 2014-09-14
    • assigned_to: Charles Rapp
     
  • Charles Rapp

    Charles Rapp - 2014-09-14

    The problem is not with the generated C# code but the C# library itself:

    C Sharp

        // The finite state machine's unique name.
        [NonSerialized]
        protected string name_;
    
        // The current state.
        [NonSerialized]
        protected State state_;
    
        // This stack is used when a push transition is taken.
        [NonSerialized]
        protected System.Collections.Stack stateStack_;
    

    The [NonSerialized] will be dropped for release 6.4.0 and the dlls updated.

    The [Serializable] is added to the AppClassContext when the SMC "-serial" option is used. See the SMC Programmer's Manual section 9: Be Persistant! which explains how to serialize/deserialize a C# FSM. You should be serializing the AppClass instance and not the AppClassContext by itself.

     

    Last edit: Charles Rapp 2014-09-14
  • DipSwitch

    DipSwitch - 2014-10-08

    Thanks works like a charm!

     
  • Charles Rapp

    Charles Rapp - 2015-02-15
    • status: open --> closed-fixed
     

Log in to post a comment.