473,395 Members | 1,742 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,395 software developers and data experts.

XmlSerialzier problem

Hello,

I have following structs

public struct User
{
public string Username;
public string Password;
public string[] Permissions;
}

public struct Users
{
public User[] RemoteUsers;
}

when I Serialize a Users struct I get following File

<?xml version="1.0" encoding="utf-8" ?>
<Users xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RemoteUsers>
<User>
<Username>Admin</Username>
<Password>21232F297A57A5A743894A0E4A801FC3</Password>
<Permissions>
<string>All</string>
</Permissions>
</User>
</RemoteUsers>
</Users>

all is OK I think..

but when I deserialize it using Users users =
(Users)serializer.Deserialize(streamReader));
I get following error:

Error in XML-document (2,2).
at System.Xml.Serialization.XmlSerializer.Deserialize (XmlReader
xmlReader, String encodingStyle)
at System.Xml.Serialization.XmlSerializer.Deserialize (TextReader
textReader)
at Remote.Users.UserControl.LoadUsers()
Nov 15 '05 #1
7 1773
Don't you need to put the [Serializable] attribute in front of (at least)
Users?

José

"Dirk Reske" <_F*******@gmx.net> a écrit dans le message de
news:eV**************@TK2MSFTNGP09.phx.gbl...
Hello,

I have following structs

public struct User
{
public string Username;
public string Password;
public string[] Permissions;
}

public struct Users
{
public User[] RemoteUsers;
}

when I Serialize a Users struct I get following File

<?xml version="1.0" encoding="utf-8" ?>
<Users xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RemoteUsers>
<User>
<Username>Admin</Username>
<Password>21232F297A57A5A743894A0E4A801FC3</Password>
<Permissions>
<string>All</string>
</Permissions>
</User>
</RemoteUsers>
</Users>

all is OK I think..

but when I deserialize it using Users users =
(Users)serializer.Deserialize(streamReader));
I get following error:

Error in XML-document (2,2).
at System.Xml.Serialization.XmlSerializer.Deserialize (XmlReader
xmlReader, String encodingStyle)
at System.Xml.Serialization.XmlSerializer.Deserialize (TextReader
textReader)
at Remote.Users.UserControl.LoadUsers()

Nov 15 '05 #2
No it doesn't work.

But, when I serialize the structure, all works fine.
I get this error only at deserializing....

"José Joye" <jose.joye@__No_SPam__bluewin__maPS_oN__.ch> schrieb im
Newsbeitrag news:Oc**************@TK2MSFTNGP09.phx.gbl...
Don't you need to put the [Serializable] attribute in front of (at least)
Users?

José

"Dirk Reske" <_F*******@gmx.net> a écrit dans le message de
news:eV**************@TK2MSFTNGP09.phx.gbl...
Hello,

I have following structs

public struct User
{
public string Username;
public string Password;
public string[] Permissions;
}

public struct Users
{
public User[] RemoteUsers;
}

when I Serialize a Users struct I get following File

<?xml version="1.0" encoding="utf-8" ?>
<Users xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RemoteUsers>
<User>
<Username>Admin</Username>
<Password>21232F297A57A5A743894A0E4A801FC3</Password>
<Permissions>
<string>All</string>
</Permissions>
</User>
</RemoteUsers>
</Users>

all is OK I think..

but when I deserialize it using Users users =
(Users)serializer.Deserialize(streamReader));
I get following error:

Error in XML-document (2,2).
at System.Xml.Serialization.XmlSerializer.Deserialize (XmlReader
xmlReader, String encodingStyle)
at System.Xml.Serialization.XmlSerializer.Deserialize (TextReader
textReader)
at Remote.Users.UserControl.LoadUsers()


Nov 15 '05 #3
BTW, is there any reason why you use XML Serialization instead of SOAP
serialization (using the SOAP formatter)?
I gave a try with the soap one and all is fine
José

"Dirk Reske" <_F*******@gmx.net> a écrit dans le message de
news:O1**************@TK2MSFTNGP12.phx.gbl...
No it doesn't work.

But, when I serialize the structure, all works fine.
I get this error only at deserializing....

"José Joye" <jose.joye@__No_SPam__bluewin__maPS_oN__.ch> schrieb im
Newsbeitrag news:Oc**************@TK2MSFTNGP09.phx.gbl...
Don't you need to put the [Serializable] attribute in front of (at least) Users?

José

"Dirk Reske" <_F*******@gmx.net> a écrit dans le message de
news:eV**************@TK2MSFTNGP09.phx.gbl...
Hello,

I have following structs

public struct User
{
public string Username;
public string Password;
public string[] Permissions;
}

public struct Users
{
public User[] RemoteUsers;
}

when I Serialize a Users struct I get following File

<?xml version="1.0" encoding="utf-8" ?>
<Users xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RemoteUsers>
<User>
<Username>Admin</Username>
<Password>21232F297A57A5A743894A0E4A801FC3</Password>
<Permissions>
<string>All</string>
</Permissions>
</User>
</RemoteUsers>
</Users>

all is OK I think..

but when I deserialize it using Users users =
(Users)serializer.Deserialize(streamReader));
I get following error:

Error in XML-document (2,2).
at System.Xml.Serialization.XmlSerializer.Deserialize (XmlReader
xmlReader, String encodingStyle)
at System.Xml.Serialization.XmlSerializer.Deserialize (TextReader
textReader)
at Remote.Users.UserControl.LoadUsers()



Nov 15 '05 #4
I don't know how soap works....I never used it...
can you post some example?

"José Joye" <jose.joye@__No_SPam__bluewin__maPS_oN__.ch> schrieb im
Newsbeitrag news:OQ*************@TK2MSFTNGP12.phx.gbl...
BTW, is there any reason why you use XML Serialization instead of SOAP
serialization (using the SOAP formatter)?
I gave a try with the soap one and all is fine
José

"Dirk Reske" <_F*******@gmx.net> a écrit dans le message de
news:O1**************@TK2MSFTNGP12.phx.gbl...
No it doesn't work.

But, when I serialize the structure, all works fine.
I get this error only at deserializing....

"José Joye" <jose.joye@__No_SPam__bluewin__maPS_oN__.ch> schrieb im
Newsbeitrag news:Oc**************@TK2MSFTNGP09.phx.gbl...
Don't you need to put the [Serializable] attribute in front of (at least) Users?

José

"Dirk Reske" <_F*******@gmx.net> a écrit dans le message de
news:eV**************@TK2MSFTNGP09.phx.gbl...
> Hello,
>
> I have following structs
>
> public struct User
> {
> public string Username;
> public string Password;
> public string[] Permissions;
> }
>
> public struct Users
> {
> public User[] RemoteUsers;
> }
>
> when I Serialize a Users struct I get following File
>
> <?xml version="1.0" encoding="utf-8" ?>
> <Users xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <RemoteUsers>
> <User>
> <Username>Admin</Username>
> <Password>21232F297A57A5A743894A0E4A801FC3</Password>
> <Permissions>
> <string>All</string>
> </Permissions>
> </User>
> </RemoteUsers>
> </Users>
>
> all is OK I think..
>
> but when I deserialize it using Users users =
> (Users)serializer.Deserialize(streamReader));
> I get following error:
>
> Error in XML-document (2,2).
> at System.Xml.Serialization.XmlSerializer.Deserialize (XmlReader
> xmlReader, String encodingStyle)
> at System.Xml.Serialization.XmlSerializer.Deserialize (TextReader
> textReader)
> at Remote.Users.UserControl.LoadUsers()
>
>



Nov 15 '05 #5
Here is a small sample that relates to your code:

José

using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Soap;

namespace ConsoleApplication7
{
[Serializable]
public struct User
{
public string Username;
public string Password;
public string[] Permissions;
}

[Serializable]
public struct Users
{
public User[] RemoteUsers;
}
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
FileStream myStream = File.Create("test.xml");
SoapFormatter myXMLFormat = new SoapFormatter();

User u1;
u1.Password = "abc";
u1.Username = "ABC";
string[] perms = new string[2];
perms[0] = "all";
u1.Permissions = perms;

Users users;
users.RemoteUsers = new User[1];
users.RemoteUsers[0] = u1;

myXMLFormat.Serialize(myStream, users);
myStream.Close();

myStream = File.OpenRead("test.xml");
Users userRead = (Users)myXMLFormat.Deserialize(myStream);

Console.ReadLine();

}
}
}

"Dirk Reske" <_F*******@gmx.net> a écrit dans le message de
news:O0**************@TK2MSFTNGP11.phx.gbl...
I don't know how soap works....I never used it...
can you post some example?

"José Joye" <jose.joye@__No_SPam__bluewin__maPS_oN__.ch> schrieb im
Newsbeitrag news:OQ*************@TK2MSFTNGP12.phx.gbl...
BTW, is there any reason why you use XML Serialization instead of SOAP
serialization (using the SOAP formatter)?
I gave a try with the soap one and all is fine
José

"Dirk Reske" <_F*******@gmx.net> a écrit dans le message de
news:O1**************@TK2MSFTNGP12.phx.gbl...
No it doesn't work.

But, when I serialize the structure, all works fine.
I get this error only at deserializing....

"José Joye" <jose.joye@__No_SPam__bluewin__maPS_oN__.ch> schrieb im
Newsbeitrag news:Oc**************@TK2MSFTNGP09.phx.gbl...
> Don't you need to put the [Serializable] attribute in front of (at

least)
> Users?
>
> José
>
> "Dirk Reske" <_F*******@gmx.net> a écrit dans le message de
> news:eV**************@TK2MSFTNGP09.phx.gbl...
> > Hello,
> >
> > I have following structs
> >
> > public struct User
> > {
> > public string Username;
> > public string Password;
> > public string[] Permissions;
> > }
> >
> > public struct Users
> > {
> > public User[] RemoteUsers;
> > }
> >
> > when I Serialize a Users struct I get following File
> >
> > <?xml version="1.0" encoding="utf-8" ?>
> > <Users xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> > <RemoteUsers>
> > <User>
> > <Username>Admin</Username>
> > <Password>21232F297A57A5A743894A0E4A801FC3</Password>
> > <Permissions>
> > <string>All</string>
> > </Permissions>
> > </User>
> > </RemoteUsers>
> > </Users>
> >
> > all is OK I think..
> >
> > but when I deserialize it using Users users =
> > (Users)serializer.Deserialize(streamReader));
> > I get following error:
> >
> > Error in XML-document (2,2).
> > at System.Xml.Serialization.XmlSerializer.Deserialize (XmlReader > > xmlReader, String encodingStyle)
> > at System.Xml.Serialization.XmlSerializer.Deserialize (TextReader > > textReader)
> > at Remote.Users.UserControl.LoadUsers()
> >
> >
>
>



Nov 15 '05 #6
"Dirk Reske" <_F*******@gmx.net> wrote in news:eVDMqvj0DHA.2752
@TK2MSFTNGP09.phx.gbl:
Hello,

I have following structs

public struct User
{
public string Username;
public string Password;
public string[] Permissions;
}

public struct Users
{
public User[] RemoteUsers;
}

when I Serialize a Users struct I get following File

<?xml version="1.0" encoding="utf-8" ?>
<Users xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RemoteUsers>
<User>
<Username>Admin</Username>
<Password>21232F297A57A5A743894A0E4A801FC3</Password>
<Permissions>
<string>All</string>
</Permissions>
</User>
</RemoteUsers>
</Users>

all is OK I think..

but when I deserialize it using Users users =
(Users)serializer.Deserialize(streamReader));
I get following error:

Error in XML-document (2,2).
at System.Xml.Serialization.XmlSerializer.Deserialize (XmlReader
xmlReader, String encodingStyle)
at System.Xml.Serialization.XmlSerializer.Deserialize (TextReader
textReader)
at Remote.Users.UserControl.LoadUsers()


When you remove the header line (<?xml .... ?> ) and then try to
deserialize again, does that work?

FB

--
Get LLBLGen Pro, the new O/R mapper for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Nov 15 '05 #7
Hello,

thanks to all, but I find the mistake myself.
I serialize a "Users" struct but tried to deserialize a "User" struct
"Frans Bouma" <pe******************@xs4all.nl> schrieb im Newsbeitrag
news:Xn********************************@207.46.248 .16...
"Dirk Reske" <_F*******@gmx.net> wrote in news:eVDMqvj0DHA.2752
@TK2MSFTNGP09.phx.gbl:
Hello,

I have following structs

public struct User
{
public string Username;
public string Password;
public string[] Permissions;
}

public struct Users
{
public User[] RemoteUsers;
}

when I Serialize a Users struct I get following File

<?xml version="1.0" encoding="utf-8" ?>
<Users xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RemoteUsers>
<User>
<Username>Admin</Username>
<Password>21232F297A57A5A743894A0E4A801FC3</Password>
<Permissions>
<string>All</string>
</Permissions>
</User>
</RemoteUsers>
</Users>

all is OK I think..

but when I deserialize it using Users users =
(Users)serializer.Deserialize(streamReader));
I get following error:

Error in XML-document (2,2).
at System.Xml.Serialization.XmlSerializer.Deserialize (XmlReader
xmlReader, String encodingStyle)
at System.Xml.Serialization.XmlSerializer.Deserialize (TextReader
textReader)
at Remote.Users.UserControl.LoadUsers()


When you remove the header line (<?xml .... ?> ) and then try to
deserialize again, does that work?

FB

--
Get LLBLGen Pro, the new O/R mapper for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma

Nov 15 '05 #8

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

Similar topics

0
by: Bruce Davis | last post by:
I'm having a problem on windows (both 2000 and XP) with a multi-threaded tkinter gui application. The problem appears to be a deadlock condition when a child thread pops up a Pmw dialog window in...
11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
0
by: Refky Wahib | last post by:
Hi I need Technical Support I finished a Great project using .Net and SQL Server and .Net Mobile Control My Business case is to implement this Program to accept about 1 Million concurrent...
9
by: Sudesh Sawant | last post by:
Hello, We have an application which communicates using remoting. There is a server which is a Windows Service. The server exposes an object which is a singleton. The client is a Web Application...
117
by: Peter Olcott | last post by:
www.halting-problem.com
17
by: Jon Slaughter | last post by:
I'm having a little trouble understanding what the slicing problem is. In B.S.'s C++ PL3rdEd he says "Becayse the Employee copy functions do not know anything about Managers, only the Employee...
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.