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

int not serializable?

Hi guys

What I am doing:
I'm saving some configuration stuff in an Class called Options. This class
has got some String, bool and an int Member. I Serialize (binary) this object
in a file.

What happens:
If I deserialize the object, all members have got their proper value except
this **** int member! Before serialize this int has got the value 10 and
after derserialize its value is 0. Is int not Serializable? I don't think so:

[Serializable, StructLayout(LayoutKind.Sequential)]
public struct Int32 : IComparable, IFormattable, IConvertible

What am I doing wrong?

Regards Alexander

My Code:
/**derserialization*/
System.IO.Stream s =
System.IO.File.OpenRead(System.Environment.Current Directory+"/trlc.opt");
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter b =
new System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter();
Object o = null;
try
{
o= b.Deserialize(s);
}
catch(System.Runtime.Serialization.SerializationEx ception)
{
....
}
if(o != null && o is Options)
{
instance = (Options)o;
}
/**serialization*/
System.IO.Stream s =
System.IO.File.OpenWrite(System.Environment.Curren tDirectory+"/trlc.opt");
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter b =
new System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter();
try
{
b.Serialize(s, Options.Instance);
}
catch(System.Runtime.Serialization.SerializationEx ception)
{
....
}
s.Flush();
s.Close();
Nov 16 '05 #1
3 9555
Hi,

is the access modifier for the int set to public ? only public fields,
members, properties are serialized & deserialized later.

Regards
Joyjit

"Alexander Wehrli" <Al*************@discussions.microsoft.com> wrote in
message news:1E**********************************@microsof t.com...
Hi guys

What I am doing:
I'm saving some configuration stuff in an Class called Options. This class
has got some String, bool and an int Member. I Serialize (binary) this object in a file.

What happens:
If I deserialize the object, all members have got their proper value except this **** int member! Before serialize this int has got the value 10 and
after derserialize its value is 0. Is int not Serializable? I don't think so:
[Serializable, StructLayout(LayoutKind.Sequential)]
public struct Int32 : IComparable, IFormattable, IConvertible

What am I doing wrong?

Regards Alexander

My Code:
/**derserialization*/
System.IO.Stream s =
System.IO.File.OpenRead(System.Environment.Current Directory+"/trlc.opt");
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter b =
new System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter();
Object o = null;
try
{
o= b.Deserialize(s);
}
catch(System.Runtime.Serialization.SerializationEx ception)
{
...
}
if(o != null && o is Options)
{
instance = (Options)o;
}
/**serialization*/
System.IO.Stream s =
System.IO.File.OpenWrite(System.Environment.Curren tDirectory+"/trlc.opt");
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter b =
new System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter();
try
{
b.Serialize(s, Options.Instance);
}
catch(System.Runtime.Serialization.SerializationEx ception)
{
...
}
s.Flush();
s.Close();

Nov 16 '05 #2
Hi,

yeah that was the point =D nasty little mistake...

Thanks a lot.

Regards Alexander

"Joyjit Mukherjee" wrote:
Hi,

is the access modifier for the int set to public ? only public fields,
members, properties are serialized & deserialized later.

Regards
Joyjit

"Alexander Wehrli" <Al*************@discussions.microsoft.com> wrote in
message news:1E**********************************@microsof t.com...
Hi guys

What I am doing:
I'm saving some configuration stuff in an Class called Options. This class
has got some String, bool and an int Member. I Serialize (binary) this

object
in a file.

What happens:
If I deserialize the object, all members have got their proper value

except
this **** int member! Before serialize this int has got the value 10 and
after derserialize its value is 0. Is int not Serializable? I don't think

so:

[Serializable, StructLayout(LayoutKind.Sequential)]
public struct Int32 : IComparable, IFormattable, IConvertible

What am I doing wrong?

Regards Alexander

My Code:
/**derserialization*/
System.IO.Stream s =
System.IO.File.OpenRead(System.Environment.Current Directory+"/trlc.opt");
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter b =
new System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter();
Object o = null;
try
{
o= b.Deserialize(s);
}
catch(System.Runtime.Serialization.SerializationEx ception)
{
...
}
if(o != null && o is Options)
{
instance = (Options)o;
}
/**serialization*/
System.IO.Stream s =
System.IO.File.OpenWrite(System.Environment.Curren tDirectory+"/trlc.opt");
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter b =
new System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter();
try
{
b.Serialize(s, Options.Instance);
}
catch(System.Runtime.Serialization.SerializationEx ception)
{
...
}
s.Flush();
s.Close();


Nov 16 '05 #3
Alexander,

Are you sure this is the case? For XmlSerialization, this is the case,
but for the Binary and SoapFormatters, by default, classes with the
Serializable attribute applied and run through the formatters have the
complete state saved, not just public members.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Alexander Wehrli" <Al*************@discussions.microsoft.com> wrote in
message news:6A**********************************@microsof t.com...
Hi,

yeah that was the point =D nasty little mistake...

Thanks a lot.

Regards Alexander

"Joyjit Mukherjee" wrote:
Hi,

is the access modifier for the int set to public ? only public fields,
members, properties are serialized & deserialized later.

Regards
Joyjit

"Alexander Wehrli" <Al*************@discussions.microsoft.com> wrote in
message news:1E**********************************@microsof t.com...
> Hi guys
>
> What I am doing:
> I'm saving some configuration stuff in an Class called Options. This
> class
> has got some String, bool and an int Member. I Serialize (binary) this

object
> in a file.
>
> What happens:
> If I deserialize the object, all members have got their proper value

except
> this **** int member! Before serialize this int has got the value 10
> and
> after derserialize its value is 0. Is int not Serializable? I don't
> think

so:
>
> [Serializable, StructLayout(LayoutKind.Sequential)]
> public struct Int32 : IComparable, IFormattable, IConvertible
>
> What am I doing wrong?
>
> Regards Alexander
>
> My Code:
> /**derserialization*/
> System.IO.Stream s =
> System.IO.File.OpenRead(System.Environment.Current Directory+"/trlc.opt");
> System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter b =
> new System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter();
> Object o = null;
> try
> {
> o= b.Deserialize(s);
> }
> catch(System.Runtime.Serialization.SerializationEx ception)
> {
> ...
> }
> if(o != null && o is Options)
> {
> instance = (Options)o;
> }
>
>
> /**serialization*/
> System.IO.Stream s =
> System.IO.File.OpenWrite(System.Environment.Curren tDirectory+"/trlc.opt");
> System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter b =
> new System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter();
> try
> {
> b.Serialize(s, Options.Instance);
> }
> catch(System.Runtime.Serialization.SerializationEx ception)
> {
> ...
> }
> s.Flush();
> s.Close();


Nov 16 '05 #4

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

Similar topics

3
by: Magnus Byne | last post by:
Hi, I have a problem using serializable transactions. In one transaction I select a single specific row from a table using a where clause (this causes it to acquire and hold a range lock). In...
0
by: xmail123 | last post by:
Hi, Hi, As was pointed out whatever you return from a WebMethod needs to be serializable to SOAP. An ArrayList is not serializable. I will be needing to return other data types from web...
8
by: xmail123 | last post by:
Hi, As was pointed out whatever you return from a WebMethod needs to be serializable to SOAP. An ArrayList is not serializable. I will be needing to return other data types from web methods. ...
5
by: Ben Terry | last post by:
I get the following compilation error: "The type or namespace name 'Serializable' could not be found (are you missing a using directive or an assembly reference?)" Can anyone tell me why the...
0
by: Poewood | last post by:
I am experimenting with saving files in binary format on the Pocket PC. When I use the attribute I get error in Compact Framework. Do i have to use the attribute to make a class serializable? ...
2
by: John | last post by:
Hi What is a Serializable class compared to a normal class? Thanks Regards
9
by: Developer | last post by:
Hi, How can one tell wsdl.exe/VS.NET web service proxy generatioon to to put on imported classes? For example, i fin your web service you use a class: class Data { }
1
by: cpnet | last post by:
I have a DataTable defined in a strongly-typed DataSet: public class MyDataSet: DataSet... { ... public class MyDataTable: DataTable... { ...}
3
by: Techno_Dex | last post by:
I'm wanting to create a Wrapper (or Extender depending on how you look at it) for a Serializable object that I then want to send over a webservice. Basically I want to create a Serializable Object,...
8
by: Techno_Dex | last post by:
Has anyone come up with a slick way to make Custom Serializable Objects to behave like DataSets when using WebServices? What I'm looking for is some way to force the WSDL generated code to create...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?

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.