title: XML Serialization and List<enum> c#
body: <p>I am trying to serialise a <code>List&lt;&gt;</code> of enums with the <code>XMLSerializer</code> when I get the following <strong>Error</strong>:</p>
  
  <pre><code>'GameDataBuilder.vshost.exe' (Managed): Loaded 'uoqssn9i'
  A first chance exception of type 'System.NullReferenceException' occurred in uoqssn9i
  A first chance exception of type 'System.TypeInitializationException' occurred in uoqssn9i
  A first chance exception of type 'System.InvalidOperationException' occurred in System.Xml.dll
  An unhandled exception of type 'System.InvalidOperationException' occurred in System.Xml.dll
  </code></pre>
  
  <p>I have taken a look inside the <code>List&lt;&gt;</code> and all of the values are valid. Using the same code I can serialize an enum (not list) and all other types (int, float etc) and Lists of those other types just fine. It just seems like the list of enum causes errors.</p>
  
  <p>Anyone came across this problem before?</p>
  
  <p>Any help would be much appreciated</p>
  
  <p><strong>edit</strong>:</p>
  
  <p>Serialize Method:</p>
  
  <pre><code>public void SerialiseToXML(XmlSerializer serializer, string directory)
  {
  
      string fileName = directory + m_Name + ".xml";
  
      if (!Directory.Exists(directory))
      {
          DirectoryInfo di = Directory.CreateDirectory(directory);
      }
  
      if (!File.Exists(fileName))
      {
          using(File.Create(fileName))
          {
          }
      }
  
      using (TextWriter textWriter = new StreamWriter(fileName))
      {
          serializer.Serialize(textWriter, m_Objects);
      }
  }
  </code></pre>
  
  <p>Serializer:</p>
  
  <pre><code>private void GenerateSerializer()
  {
      List&lt;Type&gt; dynamiclyCreatedTypes = mTypeManager.GetSerializeableTypes();
      m_Serializer = new XmlSerializer(typeof(List&lt;ISerializeable&gt;), dynamiclyCreatedTypes.ToArray());
  }
  </code></pre>
  
  <p>The List Is Generated like this:</p>
  
  <pre><code>type = typeof(List&lt;&gt;).MakeGenericType(type);
  </code></pre>