Error deserializing: The object with ID 31 implements the IObjectReference interface for which all d

K

Kenneth Baltrinic

I am getting the following error when deserializing an object that has a couple of dozen dependant objects in its object graph. Anyone who can suggest where I might begin to look to resolve problem I would greatly in debted to. Serializing the object works fine. When I try to deserialize it, I get the following error:

A first chance exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll
Additional information: The object with ID 31 implements the IObjectReference interface for which all dependencies cannot be resolved. The most likely cause is two instances of IObjectReference that have a mutual dependency on each other.

I am using the System.Runtime.Serialization.Formatters.Soap.SoapFormatter and am getting the error when calling the Deserialize() method.

Some of my objects are quasi singletons (I will explain in a minute what I mean by this) and have sererialization serogates that implement IObjectReference. So I am presuming they are the culprit somehow. Removing them from the graph one by one for testing purposes would be an obvious tactic but very difficult and time consuming in this case because it would require some effort to get the code to even run in their absense. Therefore I am really hoping some one know what sorts of issues cause this error and can explain them or point me towads good documenation. MSDN does not mention this error.

What I mean by these objects being "quasi-singletons" is that they are more like enumerations. Rather that there being a single instance of the object, there are several, but the numer is fixed; each instance of the object reflects some immutable entity in our system and contains data about it. Below is a quick example of one of these objects. The code is trunkated for simplicity sake but the real McCoy is identical except for the number of instances it supports and the number of properties it contains.

If this is not the correct way to serialize this sort of object, I would be glad to know the correct method.

--Ken

using System;
using System.Runtime.Serialization;

namespace SWIFT.Configuration.Workflow
{
/// <summary>
/// This class represents the various types of object which the swift system is comprised of.
/// </summary>
/// <remarks>
/// There is only one intance of this class per each represented object type.
/// </remarks>
[Serializable]
public class ObjectType: ISerializable
{
private enum pObjectTypeEnum
{
Workspace,
Document,
Task,
User,
DataForm
}

public static readonly ObjectType Workspace = new ObjectType(pObjectTypeEnum.Workspace, "d37bdf57-8298-416e-b880-51892b78f63a", "Workspace");
public static readonly ObjectType Document = new ObjectType(pObjectTypeEnum.Document, "289ef8ef-f56b-4b01-92b4-0191b222ddc3", "Document");
public static readonly ObjectType Task = new ObjectType(pObjectTypeEnum.Task, "e06b7ce4-3d30-45e4-bf94-118046be851f", "Task");
public static readonly ObjectType User = new ObjectType(pObjectTypeEnum.User, "17aedaeb-dfcb-4cf3-a13b-d6f02195a81f", "User");
public static readonly ObjectType DataForm = new ObjectType(pObjectTypeEnum.DataForm, "ace70065-d136-402f-96f3-0606cded7754", "Data Form");

private static readonly System.Collections.Hashtable mcTypesByID = new System.Collections.Hashtable();

public readonly string SysKey;
public readonly string Name;

private readonly int miType;

private ObjectType(pObjectTypeEnum eType, string sKey, string sName)
{
SysKey = sKey;
Name = sName;
miType = (int)eType;

mcTypesByID.Add(miType, this);
}

public new void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("TypeID", miType);
info.SetType(typeof(ObjectType.ObjectTypeSerializer));
}

internal ObjectType GetByType(int TypeID)
{
return (ObjectType)mcTypesByID[TypeID];
}

[Serializable]
private class ObjectTypeSerializer : IObjectReference, ISerializable
{
private readonly int miType;

private ObjectTypeSerializer(SerializationInfo info, StreamingContext context)
{
miType = info.GetInt32("TypeID");
}

//required as part of ISerializable
public void GetObjectData(SerializationInfo info, StreamingContext context) {}

public object GetRealObject(StreamingContext context)
{
return WFDataType.GetByType(miType);
}
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top