Solved

desrialization throwing a "Parse Error exception"

Posted on 2004-04-25
2
1,116 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

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…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

688 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