473,577 Members | 3,273 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deserializing in a different assembly... how to?

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
the file that is on disk and attempts to deserialize it and create a new
object.

The process works fine if I serialize/deserialize in the first
application, but it fails when I try to deserialize in the second
application. Here's the exception:

Parse Error, no assembly associated with Xml key
a1:http://schemas.microsoft.com/clr/nsa...eyToken%3Dnull
AdonisConfigDis k

Although it is generally not a good idea to copy/paste code like I did
(I should have 1 dll with the code I need), I am forced to do so for
some reasons I won't go into right now.

Here's my code... Does anyone have an idea of what I'm doing wrong? How
can I strip the assembly information from the serialized object?
public MemoryStream Serialize() {
MemoryStream stream = New MemoryStream();
SoapFormatter sf = New SoapFormatter(n ull, New
StreamingContex t(StreamingCont extStates.All)) ;
sf.Serialize(st ream, this);
stream.Seek(0, 0);
return stream;
}

public AdonisConfigDis k Deserialize(Mem oryStream ms) {
SoapFormatter sf = New SoapFormatter(n ull, New
StreamingContex t(StreamingCOnt extStates.All)) ;
return DirectCast(sf.D eserialize(ms), AdonisConfigDis k);
}
Thanks!

Carl

Nov 15 '05 #1
2 10334
This is an answer I posted a few days ago on a similar issue. Short answer:
factor the common data into an assembly that can be shared. Longer answer
below:

From the runtime's point of view, the true name of a type includes the name
of the assembly that contains it. If you're using C#, and create two classes
that have the same source-level name identity (including the namespaces),
you're going to have issues. The runtime believes that type F.O.G in
assembly A is not the same type as F.O.G in assembly B. Unfortunately, (or
fortunately depending on your POV) there's no way to express that difference
in C#. The custom of my people is to factor the common types into a common
assembly.

--
Mickey Williams
Author, "Microsoft Visual C# .NET Core Reference", MS Press
www.servergeek.com
"Carl Mercier" <in**@carl-mercier.nojunkp lease.com> wrote in message
news:OH******** ******@TK2MSFTN GP12.phx.gbl...
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
the file that is on disk and attempts to deserialize it and create a new
object.

The process works fine if I serialize/deserialize in the first
application, but it fails when I try to deserialize in the second
application. Here's the exception:

Parse Error, no assembly associated with Xml key
a1:http://schemas.microsoft.com/clr/nsa...%3D1.0.1419.30
011%2C%20Cultur e%3Dneutral%2C% 20PublicKeyToke n%3Dnull AdonisConfigDis k

Although it is generally not a good idea to copy/paste code like I did
(I should have 1 dll with the code I need), I am forced to do so for
some reasons I won't go into right now.

Here's my code... Does anyone have an idea of what I'm doing wrong? How
can I strip the assembly information from the serialized object?
public MemoryStream Serialize() {
MemoryStream stream = New MemoryStream();
SoapFormatter sf = New SoapFormatter(n ull, New
StreamingContex t(StreamingCont extStates.All)) ;
sf.Serialize(st ream, this);
stream.Seek(0, 0);
return stream;
}

public AdonisConfigDis k Deserialize(Mem oryStream ms) {
SoapFormatter sf = New SoapFormatter(n ull, New
StreamingContex t(StreamingCOnt extStates.All)) ;
return DirectCast(sf.D eserialize(ms), AdonisConfigDis k);
}
Thanks!

Carl

Nov 15 '05 #2
It should be noted that one can get around this using custom
serialization. Basically, if both implement the same custom serialization
scheme, then you would be able to get around this (implement ISerializable,
and have the custom serialization constructor).

However, I agree with Mickey, the common types should be factored out
into another assembly and that assembly referenced from both assemblies
sharing in the serialization/deserialization .

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Mickey Williams" <my first name at servergeek.com> wrote in message
news:ej******** ******@TK2MSFTN GP09.phx.gbl...
This is an answer I posted a few days ago on a similar issue. Short answer: factor the common data into an assembly that can be shared. Longer answer
below:

From the runtime's point of view, the true name of a type includes the name of the assembly that contains it. If you're using C#, and create two classes that have the same source-level name identity (including the namespaces),
you're going to have issues. The runtime believes that type F.O.G in
assembly A is not the same type as F.O.G in assembly B. Unfortunately, (or
fortunately depending on your POV) there's no way to express that difference in C#. The custom of my people is to factor the common types into a common
assembly.

--
Mickey Williams
Author, "Microsoft Visual C# .NET Core Reference", MS Press
www.servergeek.com
"Carl Mercier" <in**@carl-mercier.nojunkp lease.com> wrote in message
news:OH******** ******@TK2MSFTN GP12.phx.gbl...
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
the file that is on disk and attempts to deserialize it and create a new
object.

The process works fine if I serialize/deserialize in the first
application, but it fails when I try to deserialize in the second
application. Here's the exception:

Parse Error, no assembly associated with Xml key

a1:http://schemas.microsoft.com/clr/nsa...%3D1.0.1419.30 011%2C%20Cultur e%3Dneutral%2C% 20PublicKeyToke n%3Dnull
AdonisConfigDis k

Although it is generally not a good idea to copy/paste code like I did
(I should have 1 dll with the code I need), I am forced to do so for
some reasons I won't go into right now.

Here's my code... Does anyone have an idea of what I'm doing wrong? How
can I strip the assembly information from the serialized object?
public MemoryStream Serialize() {
MemoryStream stream = New MemoryStream();
SoapFormatter sf = New SoapFormatter(n ull, New
StreamingContex t(StreamingCont extStates.All)) ;
sf.Serialize(st ream, this);
stream.Seek(0, 0);
return stream;
}

public AdonisConfigDis k Deserialize(Mem oryStream ms) {
SoapFormatter sf = New SoapFormatter(n ull, New
StreamingContex t(StreamingCOnt extStates.All)) ;
return DirectCast(sf.D eserialize(ms), AdonisConfigDis k);
}
Thanks!

Carl


Nov 15 '05 #3

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

Similar topics

1
570
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 the file that is on disk and attempts to deserialize it and create a new object. The process works fine if I serialize/deserialize in the first
0
1681
by: Ken Durden | last post by:
I'm working on a client-server application where the client is controlling two devices (aka servers) which both implement the same interface contract. We have a set of about 4 assemblies which specify the interfaces and the data types which flow through the interfaces. Initially, we thought this would be enough for the client to talk with...
0
1515
by: Zsolt Domokos | last post by:
I serialised data in an assembly and I want to deserialize in different assembly but I get an exception: An unhandled exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll Additional information: File or assembly name ASSEMBLY1, or one of its dependencies, was not found. How can I deserialize it?
1
1353
by: Tim Bücker | last post by:
Hello. Are there any resources out there (because I couldn´t find any) concerning the usage of assemblies with different features in each version? In other words: I´ve got one assembly A that is using assembly B - B exists in different versions. Now I want to make it possible for A to ask B what features it supports or what data it can...
4
2204
by: Brett Romero | last post by:
Say I have this setup: public static void SomeMethod() { #if DEBUG .... #endif }
0
1391
by: Dmitrii | last post by:
My C# project has 4-configuration: Debug, Release, DebugPlus, and ReleasePlus. In each of these configurations the C# program should consume (be "linked" to) a different Assembly.dll build created by a C++/CLI multiple configuration project:: Debug, Release, DebugPlus, and ReleasePlus Assembly.dll, respectively. So far I could not find a...
1
2398
by: somequestion | last post by:
i'd like to use delegate but it is not in same assembly. how should i do to solve this... source code is like below... using B; namespace A { class A { funcA()
7
10902
by: Linda Liu[MSFT] | last post by:
Hi George, I have downloaded your sample solution and built it on my machine. I got a compilation error indicating that the type of "CustomResources" doesn't exist in the following xaml code: <Expander Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type res:CustomResources}, ResourceId=CustomExpanderStyle1}}" >
0
880
by: Jason Madison | last post by:
I would like some information on options for allowing different versions of assemblies to work together. Example: assembly1v1 makes calls to some classes in assembly2v1 A new version of assembly2 comes out assembly2v2. This has some new features in it. I want assembly1v1 to be able to use assembly2v2 but not break, even though it...
0
7845
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main...
0
7776
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8121
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8286
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5340
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3779
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3797
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1107
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.