Serialization: How use a specific Version of the internal serialization-algorithm?

Hello,

my problem is the following:

I have an object that looks like this:

[Serialized]
public class CDBPage{
public Int64 NextID;
...
public Byte[] Data;
...
};

In my test case the serialization algorithm generates 648 Bytes to save my structure with some defined data in the "Data"-Field.
The problem is that the serialized data gets stored in a file with specific boundaries of 648 Bytes (only in this example)... So if there are 10 "CDBPage"-objects are saved, they need 6480 Bytes...

There is no way to implement this in another way, because I need to address a single page in the file with: PageOffset = PageIndex * 648; /* Or any other Alignment */

In the same Version of the CLR there is no problem, of course...

But maybe next versions of the CLR will have another internal serialization standard that maybe generates 650 bytes for the same structure... Do you know what i mean? Now my file will be unuseable with the new CLR, because PageOffset != PageIndex * 648!!!!

And to convert the whole file only to use a new CLR-version is possible but I would prefer another way!!

--------------------------------------

MY QUESTION: Is there any possibility to force the CLR to use the serialization of the .NET Framework 3.0, for the next years or at least till I upgrade the databases in the way described above?

It is enough if I can apply this change only to my object "CDBPage".... But if there is a general possebility for all objects in my assembly its also ok...

Thanks for advance!
LenWinSonSoftAsked:
Who is Participating?
 
DanRollinsCommented:
My view of this is that Microsoft will be unlikely to modify the internal, default serialization in future versions.  Doing so would immeadiately break all apps that used it and that would be one of the critical issue addressed by the people who wrote it.

If that assuance is not enough, then you always have the option of writing your own serialization/deserialization handlers.

Here's a good 3-part article about serialization
   http://msdn.microsoft.com/msdnmag/issues/02/04/net/default.aspx
   http://msdn.microsoft.com/msdnmag/issues/02/07/net/default.aspx
   http://msdn.microsoft.com/msdnmag/issues/02/09/net/default.aspx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.