new XmlSerializer(typeof(MyClass)) Causing Memory corruption?
<p>I've got an application that loads an assembly dynamically:</p>

<pre><code> Assembly asm = Assembly.Load("MyClass.DLL");
 Type type = asm.GetType("MyClass");

 MyClass runningAssembly = (MyClass)Activator.CreateInstance(type);
 runningAssembly.start();
</code></pre>

<p>Once loaded and the start() method is called, this line of code is executed:</p>

<pre><code> XmlSerializer deserializer = new XmlSerializer(typeof(MyClass));
</code></pre>

<p>And the following exception is thrown:</p>

<pre><code> "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
</code></pre>

<p>I've been stumbling on the cause of this and haven't been able to get a grasp on it. Does anyone have any tips? I also cannot seem to trap this error... it blows right through the try/catch.</p>

<p>By the way, the error doesn't <em>always</em> happen. Sometimes in debug mode it works fine, but it seems like once it starts, it'll always happen even after restarting Visual Studio. A reboot clears it up and allows it to work at least once. It also happens when running from the compiled EXE.</p>

<p><strong>EDIT</strong></p>

<p>I tried the same thing but without loading the assembly dynamically. I called it as a class directly, i.e:</p>

<pre><code>MyClass c = new MyClass();
c.start();
</code></pre>

<p>And the same problem persists, so it does NOT appear to be related to being loaded dynamically.</p>
