locked
serialization problem RRS feed

  • Question

  • Hi,
    i'm doing a projct which involves talking to several  robotic internal microcontrollers. When i  build the packages i send to the different controllers i have a lot of hardware specific constants i put into those packages, like microcontroller id and motorspecific offsets. All those constants are stored in a static class, so i can write namen and do not need to write magic byte values.
    At the moment these packages are Arrays of Structs. Serialization of these arrays is no problem, i can pass them between services, as long as i hardcode the byte values in the structs. As soon as i exchange those byte values with my constands, dssproxy dies with error code 20, which is, i guess, because these constants cannot be serialized (correct me please if im wrong here).
    Is there any way i can make such a class or struct which contains a bunch of constants and is still serializable. it seem i cannot inherit from IDssSerializable with my static class, and the compiler didnt like my static struct full of constants,.....

    Thanks in advance
    Tom
    Wednesday, December 5, 2007 4:14 PM

Answers

  • The following should work:

     

        [DataContract]
        public class Constants // can't be a static class
        {
            [DataMember]
            public const byte Test = 42;
        }

     

        [DataContract]
        public struct Message
        {
            [DataMember]
            public const byte Data = Constants.Test;
        }

     

    Hope this helps,

     

    Andreas

    Wednesday, December 5, 2007 6:47 PM