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. Deserialization problems: System.Drawing.Color

Deserialization problems: System.Drawing.Color

Scheduled Pinned Locked Moved C#
csharpgraphicsjsonhelpquestion
2 Posts 2 Posters 1 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.
  • A Offline
    A Offline
    Alan Balkany
    wrote on last edited by
    #1

    Hi all, I've used the default .NET serialization for a class with a System.Drawing.Color member. The code is now in use by people, and I need to add an extra member to the class, but still deserialize older versions. It uses the SoapFormatter, so can't use the [OptionalField] attribute. So I added ISerializable to the class, which instantly caused a much bigger problem: Structs (like System.Drawing.Color) suddenly can no longer be deserialized; I get the exception message, "Top Object cannot be instantiated for element 'foreColor'". Does anyone know how I can get the SoapFormatter to read both old and new versions, and still handle structs? Thanks! Alan

    B 1 Reply Last reply
    0
    • A Alan Balkany

      Hi all, I've used the default .NET serialization for a class with a System.Drawing.Color member. The code is now in use by people, and I need to add an extra member to the class, but still deserialize older versions. It uses the SoapFormatter, so can't use the [OptionalField] attribute. So I added ISerializable to the class, which instantly caused a much bigger problem: Structs (like System.Drawing.Color) suddenly can no longer be deserialized; I get the exception message, "Top Object cannot be instantiated for element 'foreColor'". Does anyone know how I can get the SoapFormatter to read both old and new versions, and still handle structs? Thanks! Alan

      B Offline
      B Offline
      Bernhard Hiller
      wrote on last edited by
      #2

      Maybe following design could help: Create a new class by extending your previous class, i.e. public class MyNewClass : MyOldClass Then add a Version property to the (new) class. For deserialization, get that property with XmlNode versionNode = xmlDoc.SelectSingleNode("/MyNewClass/Version"); If versionNode is null, call the deserialization method of MyOldClass, otherwise use the deserialization method of MyNewClass. With the version property, you will then be able to extend further easily.

      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