Assembly serialization - how to do it?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dejan

    #1

    Assembly serialization - how to do it?

    Hello!

    I need to make an ASP.NET XML Web Service serving as an assembly
    container. Web Service loads the assembly from a given file, and
    returns that assembly to the caller.
    Since ASP.NET doesn't support serialization of objects of type
    System.Reflecti on.Assembly into XML, I decided to use SoapFormatter or
    BinaryFormatter class to serialize assembly object into memory stream,
    then construct byte array from memory stream, and finaly return that
    byte array to the caller. It seems to work.

    Problem occurs on the client side when I'm trying to deserialize
    assembly object from memory stream. Client application throws
    following exception:

    An unhandled exception of type
    'System.Runtime .Serialization. SerializationEx ception' occurred in
    mscorlib.dll
    Additional information: Insufficient state to deserialize the object.
    More information is needed.



    Here is sample of code:


    Web Service:
    [WebMethod]
    public byte[] GetAssembly( string assFile )
    {
    Assembly ass = Assembly.LoadFr om( assFile );

    IFormatter formatter = new SoapFormatter() ;
    MemoryStream stream = new MemoryStream();
    formatter.Seria lize( stream, ass );

    return stream.ToArray( );
    }




    Client application:
    [STAThread]
    static void Main(string[] args)
    {
    localhost.Assem blyContainer ac = new localhost.Assem blyContainer();

    byte[] assByteArray = ac.GetAssembly( "someFile.dll") ;

    MemoryStream stream = new MemoryStream( assByteArray );
    IFormatter formater = new SoapFormatter() ;
    Assembly ass = formater.Deseri alize( stream );
    }



    Here is the trace of memory stream, ie. serialized assembly object:

    <SOAP-ENV:Envelope xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
    xmlns:SOAP-ENC="http://schemas.xmlsoap .org/soap/encoding/"
    xmlns:SOAP-ENV="http://schemas.xmlsoap .org/soap/envelope/"
    xmlns:clr="http ://schemas.microso ft.com/soap/encoding/clr/1.0"
    SOAP-ENV:encodingSty le="http://schemas.xmlsoap .org/soap/encoding/">
    <SOAP-ENV:Body>
    <a1:UnitySerial izationHolder id="ref-1"
    xmlns:a1="http://schemas.microso ft.com/clr/ns/System">
    <Data id="ref-2">SemaphoreRes ource, Version=1.0.160 0.33496,
    Culture=neutral , PublicKeyToken= null</Data>
    <UnityType>6</UnityType>
    <AssemblyName href="#ref-2"/>
    </a1:UnitySeriali zationHolder>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>





    There is no difference if I use BinaryFormatter instead of
    SoapFormatter.

    Could anyone answer me why this doesn't work?
    Does anyone know how to serialize assembly objects?

    Thanks in advance,
    Dejan
  • Ollie

    #2
    Re: Assembly serialization - how to do it?

    why not open the file in binary mode and read the file stream and returns
    this as an array....

    witha "Dejan" <dejan.skvorc@c k.htnet.hr> wrote in message
    news:9e1fd687.0 407080311.1bd42 fc7@posting.goo gle.com...[color=blue]
    > Hello!
    >
    > I need to make an ASP.NET XML Web Service serving as an assembly
    > container. Web Service loads the assembly from a given file, and
    > returns that assembly to the caller.
    > Since ASP.NET doesn't support serialization of objects of type
    > System.Reflecti on.Assembly into XML, I decided to use SoapFormatter or
    > BinaryFormatter class to serialize assembly object into memory stream,
    > then construct byte array from memory stream, and finaly return that
    > byte array to the caller. It seems to work.
    >
    > Problem occurs on the client side when I'm trying to deserialize
    > assembly object from memory stream. Client application throws
    > following exception:
    >
    > An unhandled exception of type
    > 'System.Runtime .Serialization. SerializationEx ception' occurred in
    > mscorlib.dll
    > Additional information: Insufficient state to deserialize the object.
    > More information is needed.
    >
    >
    >
    > Here is sample of code:
    >
    >
    > Web Service:
    > [WebMethod]
    > public byte[] GetAssembly( string assFile )
    > {
    > Assembly ass = Assembly.LoadFr om( assFile );
    >
    > IFormatter formatter = new SoapFormatter() ;
    > MemoryStream stream = new MemoryStream();
    > formatter.Seria lize( stream, ass );
    >
    > return stream.ToArray( );
    > }
    >
    >
    >
    >
    > Client application:
    > [STAThread]
    > static void Main(string[] args)
    > {
    > localhost.Assem blyContainer ac = new localhost.Assem blyContainer();
    >
    > byte[] assByteArray = ac.GetAssembly( "someFile.dll") ;
    >
    > MemoryStream stream = new MemoryStream( assByteArray );
    > IFormatter formater = new SoapFormatter() ;
    > Assembly ass = formater.Deseri alize( stream );
    > }
    >
    >
    >
    > Here is the trace of memory stream, ie. serialized assembly object:
    >
    > <SOAP-ENV:Envelope xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
    > xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
    > xmlns:SOAP-ENC="http://schemas.xmlsoap .org/soap/encoding/"
    > xmlns:SOAP-ENV="http://schemas.xmlsoap .org/soap/envelope/"
    > xmlns:clr="http ://schemas.microso ft.com/soap/encoding/clr/1.0"
    > SOAP-ENV:encodingSty le="http://schemas.xmlsoap .org/soap/encoding/">
    > <SOAP-ENV:Body>
    > <a1:UnitySerial izationHolder id="ref-1"
    > xmlns:a1="http://schemas.microso ft.com/clr/ns/System">
    > <Data id="ref-2">SemaphoreRes ource, Version=1.0.160 0.33496,
    > Culture=neutral , PublicKeyToken= null</Data>
    > <UnityType>6</UnityType>
    > <AssemblyName href="#ref-2"/>
    > </a1:UnitySeriali zationHolder>
    > </SOAP-ENV:Body>
    > </SOAP-ENV:Envelope>
    >
    >
    >
    >
    >
    > There is no difference if I use BinaryFormatter instead of
    > SoapFormatter.
    >
    > Could anyone answer me why this doesn't work?
    > Does anyone know how to serialize assembly objects?
    >
    > Thanks in advance,
    > Dejan[/color]


    Comment

    Working...