Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Serialization [modified]

Serialization [modified]

Scheduled Pinned Locked Moved C#
jsonhelpquestionannouncement
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sjembek
    wrote on last edited by
    #1

    I'm trying to serialize an instance of a class with members of type bool, string, double[], double, int and an enumeration declared serializable. The class is marked [Serializable()] and doesn't have any child objects aside from the primitives mentioned. Also, it doesn't extend any other class: It's declared:

    [Serializable()]
    public sealed class EQband

    While serializing the object I get an error:

    System.Runtime.Serialization.SerializationException: Type 'CtlEQ.CtlEQ' in Assembly 'bla, Version=2.0.2386.18258, Culture=neutral, PublicKeyToken=null' is not marked as serializable.

    I can't figure out why an attempt is made to serialize some instance of the CtlEQ class. The class I'm serializing is declared within the same namespace and is used by the CtlEQ.CtlEQ class (CtlEQ holds a refference to EQBand), but is no member of it. Does anyone know why this attempt is made and how I can prevent this from happening?

    R 1 Reply Last reply
    0
    • R Robert Rohde

      Just a wild guess: Do you have an event in EQband which CtlEQ listens to?

      S Offline
      S Offline
      sjembek
      wrote on last edited by
      #2

      Errr. Yes... Does this matter?

      R 1 Reply Last reply
      0
      • S sjembek

        I'm trying to serialize an instance of a class with members of type bool, string, double[], double, int and an enumeration declared serializable. The class is marked [Serializable()] and doesn't have any child objects aside from the primitives mentioned. Also, it doesn't extend any other class: It's declared:

        [Serializable()]
        public sealed class EQband

        While serializing the object I get an error:

        System.Runtime.Serialization.SerializationException: Type 'CtlEQ.CtlEQ' in Assembly 'bla, Version=2.0.2386.18258, Culture=neutral, PublicKeyToken=null' is not marked as serializable.

        I can't figure out why an attempt is made to serialize some instance of the CtlEQ class. The class I'm serializing is declared within the same namespace and is used by the CtlEQ.CtlEQ class (CtlEQ holds a refference to EQBand), but is no member of it. Does anyone know why this attempt is made and how I can prevent this from happening?

        R Offline
        R Offline
        Robert Rohde
        wrote on last edited by
        #3

        Just a wild guess: Do you have an event in EQband which CtlEQ listens to?

        S 1 Reply Last reply
        0
        • S sjembek

          Errr. Yes... Does this matter?

          R Offline
          R Offline
          Robert Rohde
          wrote on last edited by
          #4

          Well if you bind an event of class A from class B then internally you are setting a reference from A to B. Add the following to not serialize your event:

          [field:NonSerializedAttribute()]
          public event EventHandler FooEvent;

          S 1 Reply Last reply
          0
          • R Robert Rohde

            Well if you bind an event of class A from class B then internally you are setting a reference from A to B. Add the following to not serialize your event:

            [field:NonSerializedAttribute()]
            public event EventHandler FooEvent;

            S Offline
            S Offline
            sjembek
            wrote on last edited by
            #5

            Allright, I had already set a method on [OnSerializing()] to set the event to null, following your last post. That worked, but I can see this is more graceful. Thanks for the help!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups