Solved

deserialize an object that is not referenced by the assembly.

Posted on 2004-04-22
2
418 Views
Last Modified: 2008-02-01
how can i deserialize an object that is not referenced by the current Assembly. everytime i try to do this, it throws an exception indicating that the Assembly is not recognized or found. the thing is, the object that I deserliazed was created by using Activator.CreateInstance pointing to a particular Assembly.

So when performing the deserialization process, how can i ask the deserialize operation to refer to this particular Assembly?
0
Comment
Question by:astaga
2 Comments
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 10895469
0
 
LVL 1

Accepted Solution

by:
heboh earned 125 total points
ID: 10923371
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 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

16 Experts available now in Live!

Get 1:1 Help Now