title: XmlSerializer (c#) reports There was an error reflecting type (type = List<myclass> )
body: <p>Can anyone help?</p>
  
  <p>I have a method for converting an object to a dataset. In this case the object is a collection (using LIST) of a a collection class</p>
  
  <p>Here is the code but it errors with the following error on the line XmlSerializer formatter= ...</p>
  
  <p>This is the error</p>
  
  <p>There was an error reflecting type 'System.Collections.Generic.List`1[MyNameSpace.Model.InformeVehiculo]'.</p>
  
  <pre><code>    public static DataSet TransformObjectToDataSet(System.Type type, object datos, string nombre)
      {
          XmlSerializer formatter = new XmlSerializer(type, "Coleccion" + nombre);
          MemoryStream buffer = new MemoryStream();
          formatter.Serialize(buffer, datos);
          buffer.Position = 0;
          DataSet dtsDatos = new DataSet(nombre);
          dtsDatos.ReadXml(buffer);
  
          return dtsDatos;
      }
  </code></pre>
  
  <p>I am calling the method like so</p>
  
  <pre><code>   TransformObjectToDataSet(typeof(List&lt;InformeVehiculo&gt;), objColeccionInformeVehiculo, "ColeccionInformeVehiculo");
  </code></pre>
  
  <p>objColeccionInformeVehiculo is a List</p>
  
  <p>I am a little lost, does anyone know why its failing</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>After looking further down the InnerExeption, the last one displays the following</p>
  
  <pre><code> {"Cannot serialize member MyNameSpace.Model.ObjectChangeTracker.ObjectsRemovedFromCollectionProperties of type MyNameSpace.Model.ObjectsRemovedFromCollectionProperties, because it implements IDictionary."}
  </code></pre>
  
  <p>Actually inside the InformeVehiculo i have extended it to hold a reference to InformeContracto (using partial classes, it is a model originally created by entity framework)</p>
  
  <p>InformeContrato is where its failing.</p>
  
  <p>This my class</p>
  
  <pre><code> public partial class InformeContrato : IObjectWithChangeTracker, INotifyPropertyChanged
  </code></pre>
  
  <p>InformeContrato did NOT exist unlike InformeVehiculo which existed as a partial class created by entity framework. So I created InformeContrato manually and inserted the changeTracking stuff..</p>
  
  <p>Further down I have a region which i copied from a MODEL created by Entity Framework.</p>
  
  <pre><code>    #region ChangeTracking
  
      protected virtual void OnPropertyChanged(String propertyName)
      {
          if (ChangeTracker.State != ObjectState.Added &amp;&amp; ChangeTracker.State != ObjectState.Deleted)
          {
              ChangeTracker.State = ObjectState.Modified;
          }
          if (_propertyChanged != null)
          {
              _propertyChanged(this, new PropertyChangedEventArgs(propertyName));
          }
      }
  
      protected virtual void OnNavigationPropertyChanged(String propertyName)
      {
          if (_propertyChanged != null)
          {
              _propertyChanged(this, new PropertyChangedEventArgs(propertyName));
          }
      }
  
      event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged { add { _propertyChanged += value; } remove { _propertyChanged -= value; } }
      private event PropertyChangedEventHandler _propertyChanged;
      private ObjectChangeTracker _changeTracker;
  
      //[DataMember]
      public ObjectChangeTracker ChangeTracker
      {
          get
          {
              if (_changeTracker == null)
              {
                  _changeTracker = new ObjectChangeTracker();
                  _changeTracker.ObjectStateChanging += HandleObjectStateChanging;
              }
              return _changeTracker;
          }
          set
          {
              if (_changeTracker != null)
              {
                  _changeTracker.ObjectStateChanging -= HandleObjectStateChanging;
              }
              _changeTracker = value;
              if (_changeTracker != null)
              {
                  _changeTracker.ObjectStateChanging += HandleObjectStateChanging;
              }
          }
      }
  
      private void HandleObjectStateChanging(object sender, ObjectStateChangingEventArgs e)
      {
          if (e.NewState == ObjectState.Deleted)
          {
              ClearNavigationProperties();
          }
      }
  
      protected bool IsDeserializing { get; private set; }
  
      [OnDeserializing]
      public void OnDeserializingMethod(StreamingContext context)
      {
          IsDeserializing = true;
      }
  
      [OnDeserialized]
      public void OnDeserializedMethod(StreamingContext context)
      {
          IsDeserializing = false;
          ChangeTracker.ChangeTrackingEnabled = true;
      }
  
      protected virtual void ClearNavigationProperties()
      {
          //AccesorioContrato.Clear();
      }
  
      #endregion
  </code></pre>