views:

26

answers:

1

I have a Generic.List(Of ImportedVehicle) - ImportedVehicle being a simple class as below.

There is an enum property which is marked as public.

When I serialize to XML using an XMLSerializer, the enum's value is just set to it's default value (which is NotAllocated) and doesn't actually represent the value that is set in code.

Any ideas why an enum's value would not serialize correctly?

 <Serializable()> _
Public Class ImportedVehicle
        Public Property Driver_Name As String = ""
        Public Property Driver_AssignmentType As DriverAllocationTypeEnum = DriverAllocationTypeEnum.NotAllocated
    End Class

    <Serializable()> _
    Public Enum DriverAllocationTypeEnum
        NotAllocated = 1
        NamedDriver = 2
        PoolVehicle = 3
    End Enum

XML output (regardless of the value set to Driver_AssignmentType):

<?xml version="1.0" encoding="utf-16"?>
<ArrayOfImportedVehicle xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
  <ImportedVehicle>
    <Driver_Name>Test Name</Driver_Name>
    <Driver_AssignmentType>NotAllocated</Driver_AssignmentType>
  </ImportedVehicle>
  </<ArrayOfImportedVehicle>
A: 

Answered my own question. I was being dumb. The value of the enum member was being reset accidently elsewhere in my code before the object was serialized. So it was nothing to do with the serialization process!

Chris