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

Attribute not getting Serialized

Hi

I have a c# class defined as follows:
[System.Xml.Serialization.XmlTypeAttribute(Namespac e="http://schemas.microsoft.com/wix/2003/01/wi")
[System.Xml.Serialization.XmlRootAttribute(Namespac e="http://schemas.microsoft.com/wix/2003/01/wi", IsNullable=false)]
public class Registry
{
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Key;

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public RegistryRoot Root;
}

When I serialize this class the Root attribute is not being serialized and
the Key attribute is! The above is just a snippet of the whole class
definition. The code to serialize the class I believe to be sound and I am
setting both the Key and Root properties to a valid value.

Can anyone help or at least give me ideas of where to start?

Many thanks

Julia Beresford

Nov 12 '05 #1
1 1396
Perhaps the Root field was null. If you always want an attribute, that
sometimes has an empty value then "publish" a string property instead:

public string Root {
get { return (RootKey == null) ? string.Empty : RootKey.Name; }
set { RootKey = new RegistryRoot(value); }
}
[System.Xml.Serialization.XmlIgnore()]
public RegistryRoot RootKey {
}
"Julia Beresford" <Ju************@discussions.microsoft.com> wrote in
message news:8B**********************************@microsof t.com...
Hi

I have a c# class defined as follows:
[System.Xml.Serialization.XmlTypeAttribute(Namespac e="http://schemas.microsoft.com/wix/2003/01/wi")]
[System.Xml.Serialization.XmlRootAttribute(Namespac e="http://schemas.microsoft.com/wix/2003/01/wi",
IsNullable=false)]
public class Registry
{
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Key;

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public RegistryRoot Root;
}

When I serialize this class the Root attribute is not being serialized and
the Key attribute is! The above is just a snippet of the whole class
definition. The code to serialize the class I believe to be sound and I
am
setting both the Key and Root properties to a valid value.

Can anyone help or at least give me ideas of where to start?

Many thanks

Julia Beresford

Nov 12 '05 #2

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

Similar topics

4
by: Kevin | last post by:
I have a document, lets say: <Doc> <Ele1 Att1='hello'> <Ele2 Att2='goodbye'/> </Ele1> </Doc> In XSLT I need to generate an attribute value which contains part of this document as a text...
5
by: Neil Norfolk | last post by:
I am using C# in Visual Studio 2003. I would like to serialize a class that contains, amongst other things, public delegate void DocumentsPreferencesChange(object env, Documents e); public event...
2
by: Crispin Horsfield | last post by:
It's not useful to serialize events in a class that can be serialized so in C# you can use the 'field' attribute to mark events as 'NonSerializable'.This is not available in VB. Does anyone know...
1
by: Eric | last post by:
Hi, I have a WS client. All the code is generated by VS.NET 2003. For me its seems that an attribute is not generated during sending the request in the SOAPHeader. The problem is with...
5
by: Samuel R. Neff | last post by:
Is there a way to add the NonSerialized attribute to the "Event" fields that the VB.NET compiler creates when you declare an event? I have a class that we use with binary serialization and we...
0
by: ryansupak | last post by:
Hi, I'm serializing C# objects, only I'm creating attribute-normal XML instead of (the default) element-normal XML. For each item that gets serialized, I'm programmatically applying an...
9
by: Philipp | last post by:
Hello. OK I know this is the most asked question in XML (it says in some tutorial), but still. Please give me your insight on this (as I'm a newbie). I want to store parameters for a programm in...
4
by: Theo | last post by:
Hi, i created a custom attribute that accepts an argument in the constructor to fill a property. The constructor is supposed to be called when then attribute is set but that doesn't seem to happen....
10
by: Henrik Dahl | last post by:
Hello! I have an xml schema which has a date typed attribute. I have used xsd.exe to create a class library for XmlSerializer. The result of XmlSerializer.Serialize(...) should be passed as the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...

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.