473,404 Members | 2,195 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,404 software developers and data experts.

An annoyng Serialization problem

Hello,

I'm troubling from months with a serious serialization problem that I'm not able to solve. I try to describe as simply
as I can.

1) I have a class tha does something with colors. All default values are obviously NOT serializad. Instead, they are
serialized when they are different from those of default. Sample:
Class ColorClass
Private mBackground=Color.White
Public Property Background
'Wil be serialized if mBackground not equals to Color.White
End Property
End Class

2) I have other classes (specifically they are components) that includes some properties linked to the above ColorClass.
These classes use one or more instances of the ColorClass for their pourposes, setting appropriate colors each time for
each element of the component. Sample:
Class MyComponent
Private MyTitleBackg as ColorClass
Public Sub New()
MyTitleBackg .Background=Color.Green 'Here default of ColorClass changes: will be serialized
End Sub
<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)> _
Public Property MyTitleBackg
'Get, Set, etc.
End Property
End Class

If, at design-time, I change MyTitleBackg of MyComponent to Color.Red, new value (Color.Red) WILL be correctly
serialized since it is different from BOTH the default of ColorClass and the default of MyComponent.

But here is the problem: if, at design-time I change MyComponent.MyTitleBackg to Color.White, the new value
(Color.White) WILL be NOT serialized, and regenerating assembly causes MyComponent.MyTitleBackg switch back to
Color.Green.
What happened? New value assigned at design-time (Color.White) is equal to the default of ColorClass, and therefore it
is NOT serialized; after regeneration, the designer reads and set MyComponent.MyTitleBackg to the default color of the
current instance of MyComponent (Color.Green).

This is a problem, because I want MyComponent.MyTitleBackg.Background White, NOT Green!

I confess that has not be simple understand the logic behind the problem, especially inside a medium-complessity class
hierarchy. Please note that the problem occours with any type, non only colors.

A solution should be force serialization by setting ShouldSerializexxx=True (for every property) or by deleting
defaults, but I don't consider this a solution: it's a brutality.

Ok, if is there a way to avoid this annoyng mechanism, I've not found it.

Please help me... Thank you.

Carlo


-------------------------------------------
Carlo, MCP (Windows Based Applications)
ca************@gmail.com
Milan, Italy

Nov 21 '05 #1
2 1063
Did you tried decorating the property procedures with default value
attribute. Since the serialization manager will compare value with that of
attribute.

Shatru
"Carlo, MCP" <ca************@gmail.com> wrote in message
news:et*************@TK2MSFTNGP11.phx.gbl...
Hello,

I'm troubling from months with a serious serialization problem that I'm
not able to solve. I try to describe as simply as I can.

1) I have a class tha does something with colors. All default values are
obviously NOT serializad. Instead, they are serialized when they are
different from those of default. Sample:
Class ColorClass
Private mBackground=Color.White
Public Property Background
'Wil be serialized if mBackground not equals to Color.White
End Property
End Class

2) I have other classes (specifically they are components) that includes
some properties linked to the above ColorClass. These classes use one or
more instances of the ColorClass for their pourposes, setting appropriate
colors each time for each element of the component. Sample:
Class MyComponent
Private MyTitleBackg as ColorClass
Public Sub New()
MyTitleBackg .Background=Color.Green 'Here default of ColorClass
changes: will be serialized
End Sub

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)>
_
Public Property MyTitleBackg
'Get, Set, etc.
End Property
End Class

If, at design-time, I change MyTitleBackg of MyComponent to Color.Red, new
value (Color.Red) WILL be correctly serialized since it is different from
BOTH the default of ColorClass and the default of MyComponent.

But here is the problem: if, at design-time I change
MyComponent.MyTitleBackg to Color.White, the new value (Color.White) WILL
be NOT serialized, and regenerating assembly causes
MyComponent.MyTitleBackg switch back to Color.Green.
What happened? New value assigned at design-time (Color.White) is equal to
the default of ColorClass, and therefore it is NOT serialized; after
regeneration, the designer reads and set MyComponent.MyTitleBackg to the
default color of the current instance of MyComponent (Color.Green).

This is a problem, because I want MyComponent.MyTitleBackg.Background
White, NOT Green!

I confess that has not be simple understand the logic behind the problem,
especially inside a medium-complessity class hierarchy. Please note that
the problem occours with any type, non only colors.

A solution should be force serialization by setting
ShouldSerializexxx=True (for every property) or by deleting defaults, but
I don't consider this a solution: it's a brutality.

Ok, if is there a way to avoid this annoyng mechanism, I've not found it.

Please help me... Thank you.

Carlo


-------------------------------------------
Carlo, MCP (Windows Based Applications)
ca************@gmail.com
Milan, Italy

Nov 21 '05 #2
Yes, I tried. The problem described in my post is exactly the same with both
serialization methods: using DefaultValue method or using the pair
Resetxxx/ShouldSerializexxx method.

Carlo
Did you tried decorating the property procedures with default value
attribute. Since the serialization manager will compare value with that of
attribute.

Shatru
"Carlo, MCP" <ca************@gmail.com> wrote in message
news:et*************@TK2MSFTNGP11.phx.gbl...
Hello,

I'm troubling from months with a serious serialization problem that I'm
not able to solve. I try to describe as simply as I can.

1) I have a class tha does something with colors. All default values are
obviously NOT serializad. Instead, they are serialized when they are
different from those of default. Sample:
Class ColorClass
Private mBackground=Color.White
Public Property Background
'Wil be serialized if mBackground not equals to Color.White
End Property
End Class

2) I have other classes (specifically they are components) that includes
some properties linked to the above ColorClass. These classes use one or
more instances of the ColorClass for their pourposes, setting appropriate
colors each time for each element of the component. Sample:
Class MyComponent
Private MyTitleBackg as ColorClass
Public Sub New()
MyTitleBackg .Background=Color.Green 'Here default of ColorClass
changes: will be serialized
End Sub

<DesignerSerializationVisibility(DesignerSerializa tionVisibility.Content)>
_
Public Property MyTitleBackg
'Get, Set, etc.
End Property
End Class

If, at design-time, I change MyTitleBackg of MyComponent to Color.Red,
new value (Color.Red) WILL be correctly serialized since it is different
from BOTH the default of ColorClass and the default of MyComponent.

But here is the problem: if, at design-time I change
MyComponent.MyTitleBackg to Color.White, the new value (Color.White) WILL
be NOT serialized, and regenerating assembly causes
MyComponent.MyTitleBackg switch back to Color.Green.
What happened? New value assigned at design-time (Color.White) is equal
to the default of ColorClass, and therefore it is NOT serialized; after
regeneration, the designer reads and set MyComponent.MyTitleBackg to the
default color of the current instance of MyComponent (Color.Green).

This is a problem, because I want MyComponent.MyTitleBackg.Background
White, NOT Green!

I confess that has not be simple understand the logic behind the problem,
especially inside a medium-complessity class hierarchy. Please note that
the problem occours with any type, non only colors.

A solution should be force serialization by setting
ShouldSerializexxx=True (for every property) or by deleting defaults, but
I don't consider this a solution: it's a brutality.

Ok, if is there a way to avoid this annoyng mechanism, I've not found it.

Please help me... Thank you.

Carlo


-------------------------------------------
Carlo, MCP (Windows Based Applications)
ca************@gmail.com
Milan, Italy


Nov 21 '05 #3

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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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.