none
Serialize the ExchangeService object [managed api 1.1] RRS feed

  • Question

  • Hi,

    For various reasons, I am trying to serialize the ExchangeService to an appFabric cache. It is however throwing an exception:

    Message "Object reference not set to an instance of an object." string

    StackTrace "   at System.Runtime.Serialization.DataContract.GetGetOnlyCollectionDataContract(Int32 id, RuntimeTypeHandle typeHandle, Type type, SerializationMode mode)\r\n   at System.Runtime.Serialization.XmlObjectSerializerContext.GetDataContract(RuntimeTypeHandle typeHandle, Type type)\r\n   at System.Runtime.Serialization.XmlObjectSerializerWriteContextComplex.GetDataContract(RuntimeTypeHandle typeHandle, Type type)\r\n   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithXsiType(XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle objectTypeHandle, Type objectType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle, Type declaredType)\r\n   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)\r\n   at System.Runtime.Serialization.XmlObjectSerializerWriteContextComplex.InternalSerialize(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)\r\n   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteSerializationInfo(XmlWriterDelegator xmlWriter, Type objType, SerializationInfo serInfo)\r\n   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteISerializable(XmlWriterDelegator xmlWriter, ISerializable obj)\r\n   at WriteArrayOfKeyValueOfstringstringToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , ClassDataContract )\r\n   at System.Runtime.Serialization.ClassDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)\r\n   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)\r\n   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeAndVerifyType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, Boolean verifyKnownType, RuntimeTypeHandle declaredTypeHandle)\r\n   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithXsiType(XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle objectTypeHandle, Type objectType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle, Type declaredType)\r\n   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)\r\n   at System.Runtime.Serialization.XmlObjectSerializerWriteContextComplex.InternalSerialize(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)\r\n   at System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerializeReference(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)\r\n   at WriteExchangeServiceToXml(XmlWriterDelegator , Object , XmlObjectSerializerWriteContext , ClassDataContract )\r\n   at System.Runtime.Serialization.ClassDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)\r\n   at System.Runtime.Serialization.NetDataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph, DataContract contract, Hashtable surrogateDataContracts)\r\n   at System.Runtime.Serialization.NetDataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph)\r\n   at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph)\r\n   at System.Runtime.Serialization.XmlObjectSerializer.WriteObject(XmlDictionaryWriter writer, Object graph)\r\n   at Microsoft.ApplicationServer.Caching.Utility.Serialize(Object obj, Object context, Boolean isCompressionEnabled)\r\n   at Microsoft.ApplicationServer.Caching.Utility.Serialize(Object obj, Boolean isCompressionEnabled)\r\n   at Microsoft.ApplicationServer.Caching.SimpleSendReceiveModule.SendMsgAndWait(RequestBody reqMsg, TimeSpan requestTimeout, Boolean isCompressionEnabled, IRequestTracker& tracker)\r\n   at Microsoft.ApplicationServer.Caching.SimpleClient.SendMsgAndWait(RequestBody reqMsg, IRequestTracker& tracker)\r\n   at Microsoft.ApplicationServer.Caching.DataCache.SendReceive(RequestBody reqMsg, IMonitoringListener listener)\r\n   at Microsoft.ApplicationServer.Caching.DataCache.ExecuteAPI(RequestBody reqMsg, IMonitoringListener listener)\r\n   at Microsoft.ApplicationServer.Caching.DataCache.InternalPut(String key, Object value, DataCacheItemVersion oldVersion, TimeSpan timeout, DataCacheTag[] tags, String region, IMonitoringListener listener)\r\n   at Microsoft.ApplicationServer.Caching.DataCache.<>c__DisplayClass19.<Put>b__18()\r\n   at Microsoft.ApplicationServer.Caching.MonitoringListenerFactory.EmptyListener.Microsoft.ApplicationServer.Caching.IMonitoringListener.Listen[TResult](Func`1 innerDelegate)\r\n   at Microsoft.ApplicationServer.Caching.DataCache.Put(String key, Object value)\r\n   at Microsoft.ApplicationServer.Caching.DataCache.set_Item(String key, Object value)\r\n  

    ...

    Does anyone know whether this is even possible?
    Chris

    Monday, August 29, 2011 3:37 PM

Answers

  • Hi,

    I don't know the details of the AppFabric cache, and how it serializes object instances, but the ExchangeService class is not marked as Serializable nor does it implement ISerializable.

    As such it's not meant to be serialized. You could probably work around this problem by saving the relevant properties (Service URL and/or credentials) in the cache and recreate the ExchangeService instance when you need it.

    Kind regards,
    Henning

    Thursday, September 1, 2011 4:02 PM

All replies

  • Hi,

    I don't know the details of the AppFabric cache, and how it serializes object instances, but the ExchangeService class is not marked as Serializable nor does it implement ISerializable.

    As such it's not meant to be serialized. You could probably work around this problem by saving the relevant properties (Service URL and/or credentials) in the cache and recreate the ExchangeService instance when you need it.

    Kind regards,
    Henning

    Thursday, September 1, 2011 4:02 PM
  • This is probably the answer but it is unfortunate. I'll like need some sort of DTO for the ExchangeService object.
    Thursday, September 1, 2011 5:31 PM