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

why I can serialize a class without using [Serializable]?

I have written a class in C# and I have serilized into a file .I read
somewhere that if you want a class to be serializble you must add an
attribute called [Serializable] before the class and within the namespace,I
didn't do that but I could serialize it using the following code:
try

{

XmlSerializer s = new XmlSerializer( typeof( EnviroVars) );

s.Serialize( fs, enviromental_Vars );

}

catch(Exception ee)

{

MessageBox.Show(ee.Message + "**" + ee.StackTrace + "**" + ee.Source);

}

finally

{

fs.Close();

}

thanks for your help
Nov 12 '05 #1
2 3301
[Serializable] is for runtime serialization.

Your code uses XML Serialization.
XML and Runtime serialization are different mechanisms, and they behave
differently , and are governed by different attributes.

The XML Serializer ignores the [Serializable] attribute.

-Dino
"ALI-R" <ne****@microsoft.com> wrote in message
news:uh**************@TK2MSFTNGP11.phx.gbl...
I have written a class in C# and I have serilized into a file .I read
somewhere that if you want a class to be serializble you must add an
attribute called [Serializable] before the class and within the
namespace,I
didn't do that but I could serialize it using the following code:
try

{

XmlSerializer s = new XmlSerializer( typeof( EnviroVars) );

s.Serialize( fs, enviromental_Vars );

}

catch(Exception ee)

{

MessageBox.Show(ee.Message + "**" + ee.StackTrace + "**" + ee.Source);

}

finally

{

fs.Close();

}

thanks for your help

Nov 12 '05 #2
thanks for the info.so interesting
"Dino Chiesa [Microsoft]" <di****@online.microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
[Serializable] is for runtime serialization.

Your code uses XML Serialization.
XML and Runtime serialization are different mechanisms, and they behave
differently , and are governed by different attributes.

The XML Serializer ignores the [Serializable] attribute.

-Dino
"ALI-R" <ne****@microsoft.com> wrote in message
news:uh**************@TK2MSFTNGP11.phx.gbl...
I have written a class in C# and I have serilized into a file .I read
somewhere that if you want a class to be serializble you must add an
attribute called [Serializable] before the class and within the
namespace,I
didn't do that but I could serialize it using the following code:
try

{

XmlSerializer s = new XmlSerializer( typeof( EnviroVars) );

s.Serialize( fs, enviromental_Vars );

}

catch(Exception ee)

{

MessageBox.Show(ee.Message + "**" + ee.StackTrace + "**" + ee.Source);

}

finally

{

fs.Close();

}

thanks for your help


Nov 12 '05 #3

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

Similar topics

5
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream...
10
by: Dan | last post by:
All I Am Attempting To Serialize An Object To An XML File. Here Is The Code For That public string SaveNewSurvey( MutualSurveyObject mso_TempObject, int i_JobID ) { string s_RootFileName;...
3
by: MAY | last post by:
Hi, I have a problem about serialize the form controls. I wrote a test program to test serialize a from but fail (->An unhandled exception of type...
3
by: Jerry | last post by:
Hi, I have a class like the following: class A { private B _b; A (B b) { _b = b; } ...
2
by: films | last post by:
I understand the concept. Serialization of a class will add all the sub-objects of the class to the stream if there are also serializible. So say I have: class Author {
7
by: Ben Amada | last post by:
I've created a class that I need to store in ViewState. However when I try to store it in ViewState, I get the following error: "The type 'solution.pe2' must be marked as Serializable or have a...
1
by: js | last post by:
Does anybody knows how to solve the problem? I added attribute to the following classes in Microsoft.Practices.EnterpriseLibrary.Data namespace, but I still get the error. Thanks. ...
6
by: tshad | last post by:
I had asked about this before, but have been unable to solve the problem. Could this be a problem with Web Services? I have 4 web services that I reference in this object. There is only one...
9
by: Gillard | last post by:
i get an exeption and i do not know what else to do to continue Dim sdf As New SaveFileDialog With sdf .AddExtension = True .DefaultExt = ".record" .FileName = Now.ToLongDateString .Filter =...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.