[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.remoting

Problems with serialization of assembly objects

dejan.skvorc

6/29/2004 1:53:00 PM

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.Reflection.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.SerializationException' 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.LoadFrom( assFile );

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

return stream.ToArray();
}




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

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

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



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

<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-inst...
xmlns:xsd="http://www.w3.org/2001/XMLSc...
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encod...
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envel...
xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr...
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encod...>
<SOAP-ENV:Body>
<a1:UnitySerializationHolder id="ref-1"
xmlns:a1="http://schemas.microsoft.com/clr/ns/System...
<Data id="ref-2">SemaphoreResource, Version=1.0.1600.33496,
Culture=neutral, PublicKeyToken=null</Data>
<UnityType>6</UnityType>
<AssemblyName href="#ref-2"/>
</a1:UnitySerializationHolder>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>





There is no difference if I user 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