title: Enum value '' is invalid for type > 'EnumType' and cannot be serialized
body: <p>When using DataContractSerializer to write a DataContract with a member like:</p>
  
  <pre><code>  [DataMember]
    public PropertyId PropId { get; set; }
  </code></pre>
  
  <p>It reports a serialization error:</p>
  
  <blockquote>
    <p>SerializationException:  Enum value '8493' is invalid for type
    'EnumType' and cannot be serialized. Ensure that the necessary enum
    values are present and are marked with EnumMemberAttribute attribute
    if the type has DataContractAttribute attribute.</p>
  </blockquote>
  
  <p>Yes, that particular enum value does not exist within the C# Enum definition because the PropertyId's are dynamic and may be added to the DB (but not deleted) between recompiles.  </p>
  
  <p>Since we do not wish to require a recompile of the code just because a property was added, is there any workaround for this type of issue besides typecasting and serializing as an Int32 (that's where we started from but moved to improve type safety/readability).</p>
  
  <p>We would like to use this same concept to extend type safety to even more "generic" ID's.  For instance, say something like OrderId.  There is an advantage to defining it as an enum to get the type safety throughout C#.  The actual enum values will not exist because they have a lifespan corresponding more with runtime vs compile time.</p>
  
  <p>Similar:</p>
  
  <p><a href="https://stackoverflow.com/questions/9974127/serializing-object-with-invalid-enum-value">9974127/serializing-object-with-invalid-enum-value</a></p>
  
  <p><a href="https://stackoverflow.com/questions/8913631/wcf-datacontract-class-with-enum-causes-enum-value-1-is-invalid-for-type-e">8913631/wcf-datacontract-class-with-enum-causes-enum-value-1-is-invalid-for-type-e</a></p>