Click here to Skip to main content
13,045,540 members (69,427 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 16 Aug 2012
Copyright © CodeProject, 1999-2017
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