[INFO] Exception Thrown When Trying To Deserialize An Object Whose Type Is Defined In An Assembly Which Is Loaded By Assembly.Lo


Suppose you call Assembly.LoadFrom(...) to load an assembly named SimpleAsm in which type SimpleType is defined. Then you try to serialize a SimpleType ojbect, it works fine. But as soon as you deserialize some SimpleType object, you encounter following exception:

System.Runtime.Serialization.SerializationException: Cannot find the assembly SimpleAsm, Version=xxxx, Culture=xxxx, PublicKeyToken=xxxx.

Even the call to deserialization is in SimpleAsm itselft, the exception still exists. Although it looks a little bit ridiculous, it's the proper behavior by design.


"Some extensible applications use Assembly.LoadFrom to load an assembly and then construct objects from types defined in the loaded assembly. These objects can be serialized to a stream without any trouble. However, when deserializing this stream, the formatter attempts to load the assembly by calling Assembly's Load or LoadWithPartialName method instead of calling the LoadFrom method. In most cases, the Common Language Runtime (CLR) will not be able to locate the assembly file, causing a SerializationException exception to be thrown. "


Implement and register a System.ResolveEventHandler to help CLR class loader redirect to the properly position of the assembly and reload it into memory. The handler may look like this:

public static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
        string[] strProps = args.Name.Split(new char[] {','});
        String strPath = m_codebase + strProps[0] + ".dll";
        return Assembly.LoadFrom(strPath);

m_codebase is a relative directory that your assembly resides in. Before deserialize any SimpleType objects, register your event handler to the application domain:

Thread.GetDomain().AssemblyResolve += resolveHandler;

Also remember to unregister the handler when finish deserializing SimpleType objects to avoid any side-effects that may be brought by custom event handler:

Thread.GetDomain().AssemblyResolve -= resolveHandler;


.NET 247: SerializationException on microsoft.public.vsnet.ide
Run-time Serialization

  • 0
  • 0
    觉得还不错? 一键收藏
  • 0
Chronology. In the year 2000 I was given two courses to teach: analysis and topology. The Analysis course was assigned to me due to an emergency redistribution; Topology was thrown in as an award for accepting to teach Analysis on such short notice. Algebraic topology, which covered only homotopy theory in its curriculum, was (re)introduced into the undergraduate-graduate program of the Mathematics Department (University of Manitoba) in 2004. I have taught these two courses almost continuously ever since. This book is primarily an upshot of my teaching lifestyle over these years. The level of the book, and the target audience. The book has two clearly differentiated parts: Part 1 is topology and Part 2 is homotopy. As indicated by the title of the book, we do not have any pretense to go very deeply into these subjects. On the other hand, neither could the content be described as too breezy, for we include most of the important theorems of the basic theory. The material covered in this book is on the fuzzy boundary between the undergraduate and the graduate level. One may tentatively state that Part 1 is mostly at the advanced undergraduate level, Part 2 is mostly at the early graduate level. Indeed, the Algebraic topology (Homotopy theory) course that I have been teaching has always been cross-listed, and has almost always been taken by both graduate and advanced undergraduate students. It is my hope that this book will bring this beautiful theory closer to the undergraduate curriculum.


  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助




当前余额3.43前往充值 >
领取后你会自动成为博主和红包主的粉丝 规则
钱包余额 0