XmlSerializer - There was an error reflecting type

Using C#. NET 2.0, I have a composite information class that does have the [Serializable] feature on it. I am developing an XMLSerializer class and also passing that right into the erector:

XmlSerializer serializer = new XmlSerializer(typeof(DataClass));

I am obtaining an exemption claiming:

There was a mistake mirroring type.

Inside the information class there is an additional composite object. Does this additionally require to have the [Serializable] feature, or by having it on the leading object, does it recursively use it to all things inside?

360
2022-06-09 19:29:05
Source Share
Answers: 7

I have actually been making use of the NetDataSerialiser class to serialise my domain name courses, NetDataContractSerializer Class

The domain name courses are shared in between customer and also server.

0
2022-06-25 03:23:23
Source

Also keep in mind that you can not serialize interface controls which any kind of object you intend to pass onto the clipboard has to be serializable or else it can not be passed throughout to various other procedures.

0
2022-06-09 19:38:12
Source

I also assumed that the Serializable feature needed to get on the object yet unless I'm being a full noob (I remain in the center of a late evening coding session) the adhering to jobs from the SnippetCompiler:

using System;
using System.IO;
using System.Xml;
using System.Collections.Generic;
using System.Xml.Serialization;

public class Inner
{
    private string _AnotherStringProperty;
    public string AnotherStringProperty 
    { 
      get { return _AnotherStringProperty; } 
      set { _AnotherStringProperty = value; } 
    }
}

public class DataClass
{
    private string _StringProperty;
    public string StringProperty 
    { 
       get { return _StringProperty; } 
       set{ _StringProperty = value; } 
    }

    private Inner _InnerObject;
    public Inner InnerObject 
    { 
       get { return _InnerObject; } 
       set { _InnerObject = value; } 
    }
}

public class MyClass
{

    public static void Main()
    {
        try
        {
            XmlSerializer serializer = new XmlSerializer(typeof(DataClass));
            TextWriter writer = new StreamWriter(@"c:\tmp\dataClass.xml");
            DataClass clazz = new DataClass();
            Inner inner = new Inner();
            inner.AnotherStringProperty = "Foo2";
            clazz.InnerObject = inner;
            clazz.StringProperty = "foo";
            serializer.Serialize(writer, clazz);
        }
        finally
        {
            Console.Write("Press any key to continue...");
            Console.ReadKey();
        }
    }

}

I would certainly visualize that the XmlSerializer is making use of representation over the general public buildings.

2
2022-06-09 19:37:34
Source

Remember that serialized courses have to have default (i.e. parameterless) erectors. If you have no erector in all, that is great ; yet if you have an erector with a parameter, you'll require to add the default one also.

117
2022-06-09 19:37:19
Source

All the things in the serialization chart need to be serializable.

Given that XMLSerializer is a blackbox, examine these web links if you intend to debug better right into the serialization procedure.

Changing where XmlSerializer Outputs Temporary Assemblies

HOW TO: Debug into a .NET XmlSerializer Generated Assembly

5
2022-06-09 19:36:22
Source

Look at the internal exemption that you are obtaining. It will certainly inform you which field/property it is having problem serializing.

You can exclude fields/properties from xml serialization by enhancing them with the [XmlIgnore] feature.

XmlSerializer does not make use of the [Serializable] feature, so I question that is the trouble.

437
2022-06-09 19:35:27
Source

Also realize that XmlSerializer can not serialize abstract buildings. See my inquiry here (which I have actually included the remedy code to).

XML Serialization and Inherited Types

8
2022-06-09 19:35:13
Source