Is it possible to change namespace of the type when the object is deserialized in remoting? RRS feed

  • Question

  • generally, the problem is after the files of the project are merged using ilmerge.

    When the type is deserialized it cannot find the assembly in the current directory, in spite of the fact it resides in executable.

    Initially I thought about SerializationBinder, but is it possible to apply it for remoting?

    generally is it possible to change namespace on the fly?


    • Moved by Alexander Sun Friday, May 18, 2012 9:21 AM Move to more appropriate forum (From:Visual C# General)
    Saturday, May 12, 2012 10:40 PM

All replies

  • What type of remoting are you using? TCP, WCF or others?

    What type of object you want to serializa and deserialize?

    Do you have a segment of code?



    Sunday, May 13, 2012 8:43 AM
  • Well, it is standard .NET remoting.

    I think it doesn't matter what type is serialized/deserialized as these are internal methods of the remoting when exchanging data over network.

    Generally when data comes in, framework wants to find an assembly which has that type and is trying to load the assembly from the current directory. That file doesn't exists because had been merged using ilmerge and an exception is raised.

    The stacktrace is:

    Unhandled Exception: System.Runtime.Serialization.SerializationException: Unable
     to find assembly 'X.X.X, Version=, Culture=neutral, Publ

    Server stack trace:
       at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssem
       at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(Binary
    AssemblyInfo assemblyInfo, String name)
       at System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String obje
    ctName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInf
    ormationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, Bi
    naryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
       at System.Runtime.Serialization.Formatters.Binary.ObjectMap.Create(String nam
    e, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformat
    ionA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryA
    ssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
       at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWi
    thMapTyped(BinaryObjectWithMapTyped record)
       at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWi
    thMapTyped(BinaryHeaderEnum binaryHeaderEnum)
       at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
       at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(He
    aderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAp
    pDomain, IMethodCallMessage methodCallMessage)
       at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize
    (Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCr
    ossAppDomain, IMethodCallMessage methodCallMessage)
       at System.Runtime.Remoting.Channels.CoreChannel.DeserializeBinaryResponseMess
    age(Stream inputStream, IMethodCallMessage reqMsg, Boolean bStrictBinding)
       at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.DeserializeMess
    age(IMethodCallMessage mcm, ITransportHeaders headers, Stream stream)
       at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMess
    age(IMessage msg)

    Generally I am looking for the way to map namespaces of the target object to the executable namespace...

    Sunday, May 13, 2012 9:07 AM
  • I think it doesn't matter what type is serialized/deserialized as these are internal methods of the remoting when exchanging data over network.


    you could use a SerialzationBinder to change the AssemblyName and/or TypeName when deserializing.


    Or, you could simply send the data as byte[] and construct the objects from constructors that uses this byte[] as parameter.



    Sunday, May 13, 2012 9:19 AM
  • Right, but ... How Can I assign such mapping class to Binary Formatter of the Remoting?

    Remoting when exchanges objects over network does it "in the box", I think I don't have an access to change it when deserializing occurs when object comes in? Do I?

    Sunday, May 13, 2012 9:32 AM
  • How do you serialize and deserialize the objects? Do you use a custom Formatter (that implements IRemotingFormatter)?



    Sunday, May 13, 2012 10:39 AM
  • It is done out of my scope (.net remoting engine). I am not doing any serialize/deserialize operation explicitly.

    Remoting is doing this, that is why I asked you if I can attach SerializationBinder to Remoting operations ...

    Sunday, May 13, 2012 11:53 AM
  • Why not keeping the assembly where the type is defined unmerged?
    Monday, May 14, 2012 12:48 AM
  • My goal is to have only one file: executable one ... and I am trying to do everything to make it working...

    Would it be possible to change the destination type using custom Sink in remoting?

    Monday, May 14, 2012 4:11 PM