473,699 Members | 2,135 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 10339
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
1687
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 the server. In general it is, but when an exception is generated by the server it fails to...
0
1517
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
1354
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 give to A.
4
2213
by: Brett Romero | last post by:
Say I have this setup: public static void SomeMethod() { #if DEBUG .... #endif }
0
1402
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 way to do this.
1
2406
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
10913
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
889
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 doesn't know about the new features in assembly2v2.
0
9048
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8931
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8892
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7767
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6539
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5878
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4635
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3064
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.