Click here to Skip to main content
11,803,861 members (72,081 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# serialization
Very short question:

Why does this class(TCtsPageAdmin) have to be marked [Serializable]?
I'm just trying to serialize a
TCtsPage class is marked properly.

If I mark TCtsPageAdmin properly with the [Serializable] attribute, then the error moves up the hierarchy -> the object that consumes a TCtsPageadmin object will be the target of the error.

SaveToFile failed:
Type 'Lrj.Cts.Admin.TCtsPageAdmin' in Assembly 'LrjCtsAdmin, Version=,
Culture=neutral, PublicKeyToken=null' is not marked as serializable.

public sealed class TCtsPageAdmin : ILrjObj
    public void SaveToFile(bool aUsePagePath = true)
        String aFileName;
        List<TCtsPage> lst = GetPages("*");
        aFileName = aUsePagePath ? Path.Combine(PagePath, "pages.dat") : 
        BinaryFormatter binForm = new BinaryFormatter();
            using (Stream fStream = new FileStream(aFileName, FileMode.Create, 
                                              FileAccess.Write, FileShare.None))
                binForm.Serialize(fStream, lst);
                  new InfoEventArgs(
                      String.Format("SaveToFile succeeded.\n{0}", aFileName)));
        catch (Exception ex)
              new InfoEventArgs(
                    String.Format("SaveToFile failed: \n{0}", ex.Message)));
Posted 15-Aug-12 20:41pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

All object used in TCtsPage must have a [Serializable] attribute.

Alternatively if you can use my serializers which don't require anything and are faster than the BinaryFormatter:

Seatech at 16-Aug-12 3:39am
Thank you very much for the reply.
All objects in TCtsPage are marked with the [Serializable] attribute.
Your code looks very interesting. I think I'll have a look at that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 375
1 CPallini 320
2 F-ES Sitecore 270
3 Sergey Alexandrovich Kryukov 234
4 KrunalRohit 226
0 OriginalGriff 3,000
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,755
4 Richard MacCutchan 1,187

Advertise | Privacy | Mobile
Web01 | 2.8.151002.1 | Last Updated 16 Aug 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100