0
我有一个动态加载的程序集的应用程序:新的XmlSerializer(typeof(MyClass))导致内存损坏?
Assembly asm = Assembly.Load("MyClass.DLL");
Type type = asm.GetType("MyClass");
MyClass runningAssembly = (MyClass)Activator.CreateInstance(type);
runningAssembly.start();
一旦加载和start()方法被调用,执行这行代码:
XmlSerializer deserializer = new XmlSerializer(typeof(MyClass));
而以下异常被抛出:
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
我一直在绊脚石的原因,并没有能够得到它的把握。有没有人有任何提示?我似乎也无法捕捉到这个错误......它通过try/catch正确地发挥了作用。
顺便说一句,错误没有总是发生。有时在调试模式下它可以正常工作,但它似乎一旦启动,即使重新启动Visual Studio后也会一直发生。重新启动将其清除并允许其至少工作一次。从编译的EXE运行时也会发生这种情况。
编辑
我想同样的事情,但没有动态加载的程序集。我把它叫做作为一类直接,即:
MyClass c = new MyClass();
c.start();
而同样的问题仍然存在,所以它不会出现可能与被动态加载。