I
ink
Hi All
I am relatively new to doing this and i think that i am making some king of
school boy error.
The error i am getting is on the following line of code.
XmlSerializer xs = new XmlSerializer(typeof(ImportRecord));
The error is.
"Configuration system failed to initialize"
Below i have attached the class code and the XML i am attempting to work
with.
Please if any one can see what i am doing wrong i would much appreciate a
hand
Thanks
ink
//// Code Start
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
namespace AppConfigTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
// Get the configuration file.
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
StringReader stringReader;
stringReader= new
StringReader(config.GetSection("importFormat").SectionInformation.GetRawXml());
XmlTextReader xmlReader;
xmlReader = new XmlTextReader(stringReader);
XmlSerializer xs = new XmlSerializer(typeof(ImportRecord));
ImportRecord importFormat =
(ImportRecord)xs.Deserialize(xmlReader);
}
}
[Serializable]
[XmlType("importRecord")]
public class ImportRecord
{
[XmlAttribute("TableName")]
public string TableName;
[XmlAttribute("RowIdentifier")]
public string RowIdentifier;
[XmlAttribute("IndexOfInsertion")]
public string IndexOfInsertion;
[XmlAttribute("NoOfRowsPerRecord")]
public string NoOfRowsPerRecord;
[XmlAttribute("HeaderRowIdentifier")]
public string HeaderRowIdentifier;
[XmlElement("fieldData")]
public FieldData FieldData = new FieldData();
}
[Serializable]
[XmlType("fieldData")]
public class FieldData
{
[XmlAttribute("ColumnName")]
public string ColumnName;
[XmlAttribute("FieldName")]
public string FieldName;
[XmlAttribute("ColumnIndex")]
public string ColumnIndex;
[XmlAttribute("RowIndex")]
public string RowIndex;
[XmlAttribute("Required")]
public Boolean Required;
}
}
//// Code End
//// XML String start
<importFormat>
<importRecord TableName="GoodsExpected" RowIdentifier="H"
IndexOfInsertion="0" NoOfRowsPerRecord="5" HeaderRowIdentifier="">
<fieldData ColumnName="STORAGE PROVIDER" FieldName="CompanyID"
ColumnIndex="2" RowIndex="0" Required="True" />
<fieldData ColumnName="WAREHOUSE" FieldName="WarehouseID" ColumnIndex="2"
RowIndex="1" Required="True" />
<fieldData ColumnName="ASN REFERENCE" FieldName="ReferenceID"
ColumnIndex="2" RowIndex="2" Required="True" />
<fieldData ColumnName="EXPECTED DATE" FieldName="ExpectedDate"
ColumnIndex="2" RowIndex="3" Required="True" />
<fieldData ColumnName="CUSTOMERID" FieldName="SupplierID" ColumnIndex="2"
RowIndex="4" Required="True" />
</importRecord>
<importRecord TableName="GoodsReceivedBatch" RowIdentifier="D"
IndexOfInsertion="1" NoOfRowsPerRecord="1" HeaderRowIdentifier="H">
<fieldData ColumnName="PALLET ID" FieldName="PalletID" ColumnIndex="1"
RowIndex="0" Required="False" />
<fieldData ColumnName="ITEM CODE" FieldName="ItemID" ColumnIndex="2"
RowIndex="0" Required="True" />
<fieldData ColumnName="QTY" FieldName="Qty" ColumnIndex="3" RowIndex="0"
Required="True" />
<fieldData ColumnName="ITEM DESCRIPTION" FieldName="Description"
ColumnIndex="4" RowIndex="0" Required="False" />
</importRecord>
</importFormat>
//// XML String END
I am relatively new to doing this and i think that i am making some king of
school boy error.
The error i am getting is on the following line of code.
XmlSerializer xs = new XmlSerializer(typeof(ImportRecord));
The error is.
"Configuration system failed to initialize"
Below i have attached the class code and the XML i am attempting to work
with.
Please if any one can see what i am doing wrong i would much appreciate a
hand
Thanks
ink
//// Code Start
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
namespace AppConfigTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
// Get the configuration file.
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
StringReader stringReader;
stringReader= new
StringReader(config.GetSection("importFormat").SectionInformation.GetRawXml());
XmlTextReader xmlReader;
xmlReader = new XmlTextReader(stringReader);
XmlSerializer xs = new XmlSerializer(typeof(ImportRecord));
ImportRecord importFormat =
(ImportRecord)xs.Deserialize(xmlReader);
}
}
[Serializable]
[XmlType("importRecord")]
public class ImportRecord
{
[XmlAttribute("TableName")]
public string TableName;
[XmlAttribute("RowIdentifier")]
public string RowIdentifier;
[XmlAttribute("IndexOfInsertion")]
public string IndexOfInsertion;
[XmlAttribute("NoOfRowsPerRecord")]
public string NoOfRowsPerRecord;
[XmlAttribute("HeaderRowIdentifier")]
public string HeaderRowIdentifier;
[XmlElement("fieldData")]
public FieldData FieldData = new FieldData();
}
[Serializable]
[XmlType("fieldData")]
public class FieldData
{
[XmlAttribute("ColumnName")]
public string ColumnName;
[XmlAttribute("FieldName")]
public string FieldName;
[XmlAttribute("ColumnIndex")]
public string ColumnIndex;
[XmlAttribute("RowIndex")]
public string RowIndex;
[XmlAttribute("Required")]
public Boolean Required;
}
}
//// Code End
//// XML String start
<importFormat>
<importRecord TableName="GoodsExpected" RowIdentifier="H"
IndexOfInsertion="0" NoOfRowsPerRecord="5" HeaderRowIdentifier="">
<fieldData ColumnName="STORAGE PROVIDER" FieldName="CompanyID"
ColumnIndex="2" RowIndex="0" Required="True" />
<fieldData ColumnName="WAREHOUSE" FieldName="WarehouseID" ColumnIndex="2"
RowIndex="1" Required="True" />
<fieldData ColumnName="ASN REFERENCE" FieldName="ReferenceID"
ColumnIndex="2" RowIndex="2" Required="True" />
<fieldData ColumnName="EXPECTED DATE" FieldName="ExpectedDate"
ColumnIndex="2" RowIndex="3" Required="True" />
<fieldData ColumnName="CUSTOMERID" FieldName="SupplierID" ColumnIndex="2"
RowIndex="4" Required="True" />
</importRecord>
<importRecord TableName="GoodsReceivedBatch" RowIdentifier="D"
IndexOfInsertion="1" NoOfRowsPerRecord="1" HeaderRowIdentifier="H">
<fieldData ColumnName="PALLET ID" FieldName="PalletID" ColumnIndex="1"
RowIndex="0" Required="False" />
<fieldData ColumnName="ITEM CODE" FieldName="ItemID" ColumnIndex="2"
RowIndex="0" Required="True" />
<fieldData ColumnName="QTY" FieldName="Qty" ColumnIndex="3" RowIndex="0"
Required="True" />
<fieldData ColumnName="ITEM DESCRIPTION" FieldName="Description"
ColumnIndex="4" RowIndex="0" Required="False" />
</importRecord>
</importFormat>
//// XML String END