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. ObjectHandle and SerializationException

ObjectHandle and SerializationException

Scheduled Pinned Locked Moved C#
jsonquestionannouncement
2 Posts 1 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.
  • F Offline
    F Offline
    flipdoubt
    wrote on last edited by
    #1

    The following code throws a SerializableException where it unwraps the ObjectHandle, but why? I can't find it in any of the MSDN docs and it doesn't even go away when I mark the Task as Serializable? Here is the code: --- public ArrayList GetAssemblyNamesFromHandle( AppDomain domain, string[] assemblyNames ) { ArrayList names = new ArrayList(); foreach( string assembly in assemblyNames ) { System.IO.FileInfo file = new System.IO.FileInfo( assembly ); if( file.Exists ) { string name = assembly.Replace( file.Extension, String.Empty ); System.Runtime.Remoting.ObjectHandle oh = domain.CreateInstanceFrom( assembly, String.Format( "{0}.Task1", name ) ); // Exception thrown here. Task task = (Task) oh.Unwrap(); if( task.Succeeded ) names.Add( assembly ); } } return names; } --- Here is the Exception: --- An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll Additional information: The type TaskLib.Task1 in Assembly TaskLib, Version=1.0.1326.35718, Culture=neutral, PublicKeyToken=null is not marked as serializable. ---

    F 1 Reply Last reply
    0
    • F flipdoubt

      The following code throws a SerializableException where it unwraps the ObjectHandle, but why? I can't find it in any of the MSDN docs and it doesn't even go away when I mark the Task as Serializable? Here is the code: --- public ArrayList GetAssemblyNamesFromHandle( AppDomain domain, string[] assemblyNames ) { ArrayList names = new ArrayList(); foreach( string assembly in assemblyNames ) { System.IO.FileInfo file = new System.IO.FileInfo( assembly ); if( file.Exists ) { string name = assembly.Replace( file.Extension, String.Empty ); System.Runtime.Remoting.ObjectHandle oh = domain.CreateInstanceFrom( assembly, String.Format( "{0}.Task1", name ) ); // Exception thrown here. Task task = (Task) oh.Unwrap(); if( task.Succeeded ) names.Add( assembly ); } } return names; } --- Here is the Exception: --- An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll Additional information: The type TaskLib.Task1 in Assembly TaskLib, Version=1.0.1326.35718, Culture=neutral, PublicKeyToken=null is not marked as serializable. ---

      F Offline
      F Offline
      flipdoubt
      wrote on last edited by
      #2

      By digging deeper into the sample code at ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/dncscol/html/csharp05162002.htm, I found that the type they load dynamically descends from System.MarshalByRefObject. This makes sense to me, so I just made a loader that is a MarshalByRefObject which encapsulates all the dynamic loading of Tasks within itself. Now, I instantiate the Loader in the other AppDomain and have it do its diagnostics and return a list of assembly names that contain tasks to instantiate from the current domain.

      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