Trevor Taylor

I am trying to use a simple enum as a DataMember in the State of a service, but when I try to compile the proxy build fails.

The enum is as follows:

public enum MoveStates

{

Stop,

Turn,

MoveStraight

}

Then I add it to the state as follows:

[DataMember]

public MoveStates MoveState;

The compilation error is:

Error 1 The type or namespace name 'MoveStates' could not be found (are you missing a using directive or an assembly reference ) C:\Microsoft Robotics Studio (1.5)\samples\Intro\Robotics.Intro.Proxy.IntroTypes.cs 93 17 Intro

Is there some trick to doing this, or is it simply not possible because enums cannot be serialized into the saved state

Trevor

P.S. I have a workaround which is as follows, but I don't like it:

private int _moveState = (int) MoveStates.Stop;

[DataMember]

public int MoveState

{

get { return _moveState; }

set { _moveState = (int)value; }

}



Re: Microsoft Robotics - Community Using enums in service State?

Ben Axelrod

Hi Trevor,

You have to label the enum with [DataContract].

-Ben




Re: Microsoft Robotics - Community Using enums in service State?

Trevor Taylor

Doh!

Thanks Ben :-)

Trevor