Note that there are some explanatory texts on larger screens.

plurals
  1. POThere was an error reflecting type - XML Serialization issue
    primarykey
    data
    text
    <p>I have a Dictionary object which needs to be written into an XML file. The dictionary contains String type as Key and a custom class's Object (Deriving from System.Windows.Forms.Control ) as Value.</p> <pre><code>namespace SharpFormEditorDemo { [Serializable] public static class common { public static Dictionary&lt;String,CommonControl &gt; dicControls = new Dictionary&lt;string, CommonControl&gt;(); public static Object objSelected = new Object(); public static int ctrlId = 0; //The serialization and Deserialization methods. public static void Serialize(XmlTextWriter xmlTextWriter,Dictionary&lt;String,CommonControl&gt; dic) { xmlTextWriter.WriteStartDocument(); ControlSerializer file = new ControlSerializer(dic); XmlSerializer xmlSerializer = new XmlSerializer(typeof(ControlSerializer)); xmlSerializer.Serialize(xmlTextWriter, file); xmlTextWriter.WriteEndDocument(); } } </code></pre> <p>The class CommonControl is like this</p> <pre><code>namespace SharpFormEditorDemo { public class CommonControl : System.Windows.Forms.Control { //private List&lt;String&gt; controls; private String sql; private int minVal; //Minimum value for a field private int maxVal; //Maximum value for a field private string displayValue; //Display Value private string keyValue; //Key Value private string clickEvent; //Click event private string selectedIndexChangeEvent; //Combo box event. private string validateEvent; //Validated event. public string SelectedIndexChangeEvent { get { return selectedIndexChangeEvent; } set { selectedIndexChangeEvent = value; } } public string ClickEvent { get { return clickEvent; } set { clickEvent = value; } } public string ValidateEvent { get { return validateEvent; } set { validateEvent = value; } } public string KeyValue { get { return keyValue; } set { keyValue = value; } } public string DisplayValue { get { return displayValue; } set { displayValue = value; } } public int MinVal { get { return minVal; } set { minVal = value; } } public int MaxVal { get { return maxVal; } set { maxVal = value; } } public String Sql { get { return sql; } set { sql = value; } } //public List&lt;String&gt; Controls //{ // get { return controls; } // set { controls = value; } //} } } </code></pre> <p>The class CommonControl is a deriving from Controls class.</p> <p>What I want to do is to write the Above said dictionary to an XML file.</p> <pre><code>[Serializable] public class ControlSerializer : ISerializable { public ControlSerializer() { } private Dictionary&lt;String, CommonControl&gt; dicCtrl; public Dictionary&lt;String, CommonControl&gt; DicCtrl { get { return dicCtrl; } set { dicCtrl = value; } } public ControlSerializer(Dictionary&lt;String, CommonControl&gt; dic) { this.DicCtrl = dic; } public void GetObjectData(SerializationInfo info, StreamingContext context) { throw new NotImplementedException(); } } </code></pre> <p>for that I'm using the ControlSerializer class</p> <p>And in calling it like this</p> <pre><code> try { XmlTextWriter xlw = new XmlTextWriter(@"D:\Test.xml", null); common.Serialize(xlw, common.dicControls); } catch (Exception exShow) { </code></pre> <p>The problem is that I'm getting an exception saying "There was an error reflecting type 'SharpFormEditorDemo.ControlSerializer'."</p> <p>But I'm getting the type using typeof operator. Baffled on why this is happening. Sorry If I'm too lengthy but wanted to give the full picture.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload