473,396 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.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.SerializationExcepti on' 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-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.microsoft.com/soap/encoding/clr/1.0"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<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 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
Nov 21 '05 #1
1 7184
why not open the file in binary mode and read the file stream and returns
this as an array....

witha "Dejan" <de**********@ck.htnet.hr> wrote in message
news:9e**************************@posting.google.c om...
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.SerializationExcepti on' 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-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.microsoft.com/soap/encoding/clr/1.0"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<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 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

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Vladimir Semenov | last post by:
Hi, I'm trying to serialize a type contained in assembly referering to another assembly in GAC. XmlSerializer xs = new XmlSerializer( typeof(TransferParentData ) ); The code above throws...
2
by: Carl Mercier | last post by:
Hi! I have 2 different applications/assembly. The first one creates an object and serializes it to a textfile on disk. The second one has the the exact same class (copied/pasted). It reads...
0
by: Fruber Malcome | last post by:
I'm getting a very weird exception and hoping someone may be able to help. I have an Office Add-In that lives in a .dll (for email reference ai.dll) ai.dll makes calls into the core part of the...
2
by: Cornu Nicolas | last post by:
Hello, The above code generate the above error. The not found assembly is different at each execution. -------------------------------------------------------------------------- public void...
0
by: Martinh | last post by:
Hi After invoking RetrieveData in a WebService I recieve the following response in a new window... I am running Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573 ...
6
by: mookid8000 | last post by:
Hi group! Is it possible to scan an assembly *which has NOT been added as a reference* for types, and dynamically create instances of the loaded types? I have a program, MyProgram.exe, which...
0
by: Frank Rizzo | last post by:
Hello, I have a click-once/SmartClient app and the "Generate serialization assembly" option under Project Properties/Build is set to Auto. When I run msbuild from the command line, sgen.exe...
7
by: chage | last post by:
Hi, I have been searching around to try adding reference assembly to another assembly during runtime, programatically. Is this possible in .Net? The reason for this is because i am having...
0
by: =?Utf-8?B?Y211cmFsaQ==?= | last post by:
I am serializing/deserializing a class (Class1) using the XmlSerializer object in the System.Xml.Serialization namespace in .Net 2.0. Class1 has some strings and ints and two lists of other simple...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.