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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Problem with serializing objects

Problem with serializing objects

Scheduled Pinned Locked Moved .NET (Core and Framework)
helpquestion
2 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.
  • M Offline
    M Offline
    Marco M
    wrote on last edited by
    #1

    i have 2 modules (exe) and i'm serializing a certain object with one module and i want to deserialize it with the other one.. but the framework throws an exception coz the assembly is not the same one it was serialized from.. any clue ?? thanx shakoosh

    V 1 Reply Last reply
    0
    • M Marco M

      i have 2 modules (exe) and i'm serializing a certain object with one module and i want to deserialize it with the other one.. but the framework throws an exception coz the assembly is not the same one it was serialized from.. any clue ?? thanx shakoosh

      V Offline
      V Offline
      Vega02
      wrote on last edited by
      #2

      I had a similar problem in the project I'm working on now. You need to ensure that the type that is being serialized exists in both assemblies. For example, say that you have the following setup: ASSEMBLY 1: - Module1.cs ASSEMBLY 2: - Module2.cs And assume that each of those files has the code for some class Foo in it. Even if the code for Foo is byte-for-byte the same in both files, the framework will throw an error when attempting to deserialize because it's trying to instantiate the assembly in which the object was first created. The important fact here is that it's extremely difficult to separate a class from its containing assembly. The solution that I ended up implementing: ASSEMBLY 1: - Module1.cs - References [ASSEMBLY FOO] ASSEMBLY 2: - Module2.cs - References [ASSEMBLY FOO] ASSEMBLY FOO: - Foo.cs Here, simply remove the code for Foo from Module1.cs and Module2.cs, putting it into Foo.cs in a different assembly instead. If you reference ASSEMBLY FOO from both modules, the framework will now correctly locate the required assembly and deserialize the class. There may in fact be an alternative method to implementing this, but this is the most straightforward method that I know of. It's also the one that worked for my project. :)

      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