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

Xml serialization problem

Hi,

I have two public enums types each defined in a class (PolarDiagram and
KDiagram) in a namespace (RTech.Graphic)
I try to serialize this class with XmlSerializer without success
A suggestion ?
Thank's
Polo

[Serializable()]
public class Template
{
[XmlAttribute()]
public RTech.Graphic.PolarDiagram.ViewMode View =
RTech.Graphic.PolarDiagram.ViewMode.HalfMode;
[XmlAttribute()]
public RTech.Graphic.KDiagram.ViewMode View2 =
RTech.Graphic.KDiagram.ViewMode.TwoSide;
}
Nov 16 '05 #1
6 2171
Hi,

It works for me:

XmlSerializer ser = new XmlSerializer (typeof (Template));
Template template = new Template ();
ser.Serialize (new System.IO.StreamWriter (@"C:\test.xml"), template);

--
Regards,
Peter Jausovec
(http://blog.jausovec.net)
Polo" <pb@rtech.be> wrote in message
news:41***********************@news.skynet.be...
Hi,

I have two public enums types each defined in a class (PolarDiagram and
KDiagram) in a namespace (RTech.Graphic)
I try to serialize this class with XmlSerializer without success
A suggestion ?
Thank's
Polo

[Serializable()]
public class Template
{
[XmlAttribute()]
public RTech.Graphic.PolarDiagram.ViewMode View =
RTech.Graphic.PolarDiagram.ViewMode.HalfMode;
[XmlAttribute()]
public RTech.Graphic.KDiagram.ViewMode View2 =
RTech.Graphic.KDiagram.ViewMode.TwoSide;
}

Nov 16 '05 #2
I confirm that it doesn't work at me !

If I remove one enum it works but with the two not (Note that the template
is not the the RTech.Graphic namespace)
A+
Nov 16 '05 #3
Does the code compile ? What error do you get ?

--
Regards,
Peter Jausovec
(http://blog.jausovec.net)
"Polo" <pb@rtech.be> wrote in message
news:41***********************@news.skynet.be...
I confirm that it doesn't work at me !

If I remove one enum it works but with the two not (Note that the template
is not the the RTech.Graphic namespace)
A+

Nov 16 '05 #4
Hi Polo,
I don't know what stops your class from working. Does it have any
constructors? If so it must have a default constructor too. Try to be more
explicit when defining serialization options.

Here is a working sample of a serializable class with two enum values:
using System;
using System.IO;
using System.Xml.Serialization;
using System.Windows.Forms;

namespace Serialize
{
public enum Values{A,B}
public enum ValuesB{C,D}

[XmlRoot("TryIt")]
public class Test
{
private Values v1;
private ValuesB v2;

[XmlAttribute("ValueOne")]
public Values V1
{
get{return v1;}
set{v1=value;}
}

[XmlAttribute("ValueTwo")]
public ValuesB V2
{
get{return v2;}
set{v2=value;}
}
}

public class MainClass
{
public static void Main()
{
Test t=new Test();
t.V1=Values.A;
t.V2=ValuesB.C;

XmlSerializer serializer=new XmlSerializer(typeof(Test));
FileStream fs=new FileStream(string.Format("{0}/output.xml",
Application.StartupPath),
FileMode.Create, FileAccess.Write);
try
{
serializer.Serialize(fs,t);
}
finally
{
fs.Close();
}
}
}
}

This self contained little app will generate a file that contains this:
<?xml version="1.0"?>
<TryIt xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ValueOne="A"
ValueTwo="C" />

/Hugo

On Tue, 16 Nov 2004 10:05:32 +0100, Polo wrote:
Hi,

I have two public enums types each defined in a class (PolarDiagram and
KDiagram) in a namespace (RTech.Graphic)
I try to serialize this class with XmlSerializer without success
A suggestion ?
Thank's
Polo

[Serializable()]
public class Template
{
[XmlAttribute()]
public RTech.Graphic.PolarDiagram.ViewMode View =
RTech.Graphic.PolarDiagram.ViewMode.HalfMode;
[XmlAttribute()]
public RTech.Graphic.KDiagram.ViewMode View2 =
RTech.Graphic.KDiagram.ViewMode.TwoSide;
}

Nov 16 '05 #5
Yes It is a runtime error
Informations supplémentaires : Une erreur s'est produite lors de la
réflexion du type 'DocWin.Template'.
A error occurs in the
reflexion of type 'DocWin.Template'

A+

"Peter Jausovec" <pe***@jausovec.net> a écrit dans le message de
news:%2***************@TK2MSFTNGP11.phx.gbl...
Does the code compile ? What error do you get ?

--
Regards,
Peter Jausovec
(http://blog.jausovec.net)
"Polo" <pb@rtech.be> wrote in message
news:41***********************@news.skynet.be...
I confirm that it doesn't work at me !

If I remove one enum it works but with the two not (Note that the template is not the the RTech.Graphic namespace)
A+


Nov 16 '05 #6
In fact I have default constructor
I have in a DLL named Graphic.dll
namespace RTech.Graphic
{
public class PolarDiagram
{
public enum ViewMode
{
....
}
....
}
public class KDiagram
{
public enum ViewMode
{
....
}
....
}
}

And I have a EXE
Using RTech.Graphic;
namespace DocWin
{
public class Template
{
[XmlAttribute()]
public RTech.Graphic.PolarDiagram.ViewMode View1 =
RTech.Graphic.PolarDiagram.ViewMode.HalfMode;
[XmlAttribute()]
public RTech.Graphic.KDiagram.ViewMode View2 =
RTech.Graphic.KDiagram.ViewMode.OneSide;
//If I remove this last line It works but with the two
definitions no
.....
}
}

"Hugo Wetterberg" <hu*************@smi.mas.lu.se> a écrit dans le message de
news:15*****************************@40tude.net...
Hi Polo,
I don't know what stops your class from working. Does it have any
constructors? If so it must have a default constructor too. Try to be more
explicit when defining serialization options.

Here is a working sample of a serializable class with two enum values:
using System;
using System.IO;
using System.Xml.Serialization;
using System.Windows.Forms;

namespace Serialize
{
public enum Values{A,B}
public enum ValuesB{C,D}

[XmlRoot("TryIt")]
public class Test
{
private Values v1;
private ValuesB v2;

[XmlAttribute("ValueOne")]
public Values V1
{
get{return v1;}
set{v1=value;}
}

[XmlAttribute("ValueTwo")]
public ValuesB V2
{
get{return v2;}
set{v2=value;}
}
}

public class MainClass
{
public static void Main()
{
Test t=new Test();
t.V1=Values.A;
t.V2=ValuesB.C;

XmlSerializer serializer=new XmlSerializer(typeof(Test));
FileStream fs=new FileStream(string.Format("{0}/output.xml",
Application.StartupPath),
FileMode.Create, FileAccess.Write);
try
{
serializer.Serialize(fs,t);
}
finally
{
fs.Close();
}
}
}
}

This self contained little app will generate a file that contains this:
<?xml version="1.0"?>
<TryIt xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ValueOne="A"
ValueTwo="C" />

/Hugo

On Tue, 16 Nov 2004 10:05:32 +0100, Polo wrote:
Hi,

I have two public enums types each defined in a class (PolarDiagram and
KDiagram) in a namespace (RTech.Graphic)
I try to serialize this class with XmlSerializer without success
A suggestion ?
Thank's
Polo

[Serializable()]
public class Template
{
[XmlAttribute()]
public RTech.Graphic.PolarDiagram.ViewMode View =
RTech.Graphic.PolarDiagram.ViewMode.HalfMode;
[XmlAttribute()]
public RTech.Graphic.KDiagram.ViewMode View2 =
RTech.Graphic.KDiagram.ViewMode.TwoSide;
}

Nov 16 '05 #7

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

Similar topics

4
by: David K | last post by:
we are having a problem when trying to serilalize and deserialize DataTable When replacing the container to be ListArray or HashTable everything works fine The code is very straight forward (...
37
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined...
0
by: ktn | last post by:
Hi all, I'm a .NET beginner and I've got a problem on a program where I try to do an XML serialization. I get the following error : "An unmanaged exception of type...
1
by: andrewcw | last post by:
There is an error in XML document (1, 2). I used XML spy to create the XML and XSD. When I asked to have the XML validated it said it was OK. I used the .net SDK to generate the class. I have...
2
by: ofer | last post by:
Hi, I am working with the beta version of the new .net framework (Whidbey) and I encountered a problem with serialization that did'nt exist in the .net 2003 the situation is like this : I have...
0
by: umhlali | last post by:
I get the following exception when my VB.NET app calls a Java web service that returns an array of objects. The same call works for a single object though. So looks like there is no problem...
5
by: Harold Howe | last post by:
I am having a problem deserializing objects from a library when the following conditions exist: 1- The library is strongly named 2- The serialized file was created with version 1.0 of the...
2
by: Norman Chong | last post by:
Hiddeldi ho, I want to save an object so that I can use its content after I restart my program. I tried to solve this with serialization because someone told me that this is the correct way for...
4
by: mijalko | last post by:
Hi, I have inherited my class from System.Drawing.Printing.PrintDocument and I wish to serialize this object using XmlSerializer. And I get exception "There was an error reflecting type ...". If I...
2
by: mkvenkit.vc | last post by:
Hello, I hope this is the right place to post a question on Boost. If not, please let me know where I can post this message and I will do so. I am having a strange problem with std::string as...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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,...

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.