473,405 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Deserialize XML string to Object error

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(Configur ationUserLevel.None);

StringReader stringReader;
stringReader= new
StringReader(config.GetSection("importFormat").Sec tionInformation.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

Oct 18 '07 #1
4 3627
On Oct 18, 1:50 pm, "ink" <i...@notmyemail.comwrote:
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"
That sounds unlikely. It seems much more likely that it's *actually*
failing on this line:

System.Configuration.Configuration config =

ConfigurationManager.OpenExeConfiguration(Configur ationUserLevel.None);

Could you check this carefully, preferrably in the debugger, with a
fresh build, stepping through the code one line at a time and seeing
if it genuinely gets to the XmlSerializer constructor line?

Jon

Oct 18 '07 #2
ink
Hi Jon

I have commented out everything except this line.

XmlSerializer xs = new XmlSerializer(typeof(ImportRecord));

and still it fails.

ink


"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:11*********************@i13g2000prf.googlegro ups.com...
On Oct 18, 1:50 pm, "ink" <i...@notmyemail.comwrote:
>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"

That sounds unlikely. It seems much more likely that it's *actually*
failing on this line:

System.Configuration.Configuration config =

ConfigurationManager.OpenExeConfiguration(Configur ationUserLevel.None);

Could you check this carefully, preferrably in the debugger, with a
fresh build, stepping through the code one line at a time and seeing
if it genuinely gets to the XmlSerializer constructor line?

Jon
Oct 18 '07 #3
is your app.config / web.config file valid? missing section handlers,
etc - try removing (or renaming) this file...

Marc
Oct 18 '07 #4
ink
There was a funny Char in my app.config file so you were correct.


"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:11*********************@i13g2000prf.googlegro ups.com...
On Oct 18, 1:50 pm, "ink" <i...@notmyemail.comwrote:
>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"

That sounds unlikely. It seems much more likely that it's *actually*
failing on this line:

System.Configuration.Configuration config =

ConfigurationManager.OpenExeConfiguration(Configur ationUserLevel.None);

Could you check this carefully, preferrably in the debugger, with a
fresh build, stepping through the code one line at a time and seeing
if it genuinely gets to the XmlSerializer constructor line?

Jon
Oct 18 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: pb | last post by:
Hi, I'm having problems deploying a project to win2003. It is currently on win2000 server and works fine - it also works fine on my development machine - win2003. Both my machine and the new...
3
by: Amsteel | last post by:
I got something like this in VB.Net <Serializable()> Public Class YQProfileC Inherits CollectionBase Public Sub Save2File(ByVal FileName As String) Dim IFormatter As New BinaryFormatter() Dim...
2
by: PCH | last post by:
I have 2 functions, one to serialize an object, and one to deserialize it. I can serialize just fine, the problem is when I try to deserialize it later... I get an error: {"Invalid...
2
by: alexandre martins | last post by:
Every time i try to make Deserialize the computer gives me the folowing error: "End of Stream encountered before parsing was complete" the code that i'm running is simple and is based on an...
4
by: George Addison | last post by:
I understand this might not be the optimal method of deserialization, but how can I deserialize a class to itself? Something like: Public Sub New(Optional ByVal filename as string = Nothing)...
8
by: Frank Rizzo | last post by:
How do I serialize Font object into a string that I can store in either INI file or the registry (I know it’s a bad thing, but need to do it nevertheless). Then, also, how do I deserialize it from...
0
by: Matt S | last post by:
Hello, I'm trying to build a C# client to consume an AXIS Web Service (running SOAP over HTTP). The Web Service encodes full server-side exception traces in the Soap Fault > Detail element...
2
by: Thomas S | last post by:
Any suggestions on how to deserialize an object from one line of XML? I'm trying to deserialize multiple objects from one XML document, each object on one line of the file. The serialization is...
4
by: Anbu | last post by:
Hi All, I need to Deserialize the SoapService's SoapEnvelope response object. Here is the Body of the SoapEnvelope received as respone, <q1:serviceResponse...
11
by: wpmccormick | last post by:
I've a complex problem: I'm deserializing a very long string of XML into a very large object foo: <foo> ....... <bar>sometimes a simple string is here</bar> ....... </foo>
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.