Solved

desrialization throwing a "Parse Error exception"

Posted on 2004-04-25
2
1,030 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
Comment Utility
0
 
LVL 1

Accepted Solution

by:
heboh earned 500 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now