我有一个动态加载程序集的应用程序:
Assembly asm = Assembly.Load("MyClass.DLL");
Type type = asm.GetType("MyClass");
MyClass runningAssembly = (MyClass)Activator.CreateInstance(type);
runningAssembly.start();
XmlSerializer deserializer = new XmlSerializer(typeof(MyClass));
并引发以下异常:
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
我一直在这件事的起因上磕磕绊绊,没能弄清楚。有人有什么建议吗?我似乎也无法捕捉这个错误。。。它在试/接球时就吹了。
总是
发生了。有时在调试模式下,它工作得很好,但似乎一旦启动,即使在重新启动Visual Studio之后,它也总是会发生。重新启动会清除它,并允许它至少工作一次。从编译的EXE运行时也会发生这种情况。
编辑
我尝试了同样的方法,但没有动态加载程序集。我直接把它称为一个类,即:
MyClass c = new MyClass();
c.start();
同样的问题仍然存在,因此它似乎与动态加载无关。