views:

367

answers:

3

Guys, I have the follow VB.NET class definition:

<Serializable()> Partial Public Class Customers
End Class

Inside another file I have the same thing (with different methods and variables of course). When I compile, I get the following error:

Attribute 'SerializableAttribute' cannot be applied multiple times.

The error is pretty self explanatory. My question is though, if I just mark the one class as Serializable(), can I assume the entire class with be marked as serializable()? In other words, Do I only need the serializable() tag in 1 spot in the class?

+4  A: 

You only need it marked once per class so in a class with more than one 'partial' definitation, you should just remove it from all the other files. The whole 'partial' thing is just a way of visualizing your code so when you apply it once, it will be for the whole class.

JasonRShaver
Thanks for clearing this up. I thought it was that easy, but I just wanted to be sure.
icemanind
+3  A: 

Yes, you only need to put it in one of the Partial Classes:
http://msdn.microsoft.com/en-us/library/wa80x488.aspx

"At compile time, attributes of partial-type definitions are merged."

Badaro
A: 

I am facing the same issue which been in initial of the thread. I have one partial class and it is serialized. now i have extended that class and created one public property of that class. But i am not able to get that propetry in serialization. Please suggest me what to do ?

Ex. [Serializable()] public partial class A {}

public partial class A{ public string myMessage {get;set;}

}

I need myMessage to be serialized.

My problem
Serialization happens to a class, not to a method, right?
icemanind