Serializable Partial Classes

Guys, I have the following 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:

The SerializableAttribute attribute cannot be used multiple times.

The error is pretty clear. My question is, though, if I just mark one class as Serializable (), can I take the whole class marked as serializable ()? In other words, I only need the serializable () tag in 1 place in the class?

+4
source share
2 answers

You will need only once for each class, so in a class with more than one β€œpartial” certainty, you just need to remove it from all other files. The whole β€œpartial” thing is just a way to visualize your code, so when you apply it once, it will be for the whole class.

+7
source

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, the attributes of the partial type definitions are combined.

+6
source

All Articles