Solved

desrialization throwing a "Parse Error exception"

Posted on 2004-04-25
2
1,080 Views
Last Modified: 2007-12-19
I am trying to deserialize using the SoapFormatter.

The object I am trying to deserialzed is not directly referenced by the current assembly and class.
However, i added the particular assembly to the current AppDomain using the AppDomain.CurrentDomain.Load(rawAssembly, rawSymbolStore);

I thought this would work. but instead it throws an exception with the message:
Message      "Parse Error, no assembly associated with Xml key a3:http://schemas.microsoft.com/clr/nsassem/TestAgent/AgentPlay%2C%20Version%3D1.0.1577.29029%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull AgentPlay"      string


The required assembly is already loaded to the currently utilized AppDomain, how can I get the SoapFormatter to refer to the Assembly, when performing the desrialization process.

thanks kindly in advanced.


0
Comment
Question by:astaga
2 Comments
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 10916351
0
 
LVL 1

Accepted Solution

by:
heboh earned 500 total points
ID: 10923366
the easiest thing to do is to implement the AppDomain.CurrentDomain.AssemblyResolve event before performing the desrialization operation. Have a look at the following code :

// Deserialization method
ResolveEventHandler lca = new ResolveEventHandler(LoadComponentAssembly);

AppDomain.CurrentDomain.AssemblyResolve += lca;
            
object anObject = sf.Deserialize(sw.BaseStream);

AppDomain.CurrentDomain.AssemblyResolve -= lca;

// Method for event

private static Assembly LoadComponentAssembly(object sender, ResolveEventArgs args)
{
   string simpleName = args.Name.Substring(0, args.Name.IndexOf(','));
  string assemblyPath = Path.Combine("..\\Agent\\",  simpleName + ".dll");
  return Assembly.LoadFrom(assemblyPath);
}
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question