title: Accessing protected memory in C# via COM interop
body: <p>I am making a DLL "Plugin" for a EXE. The EXE calls a function in the DLL with an Object as a parameter, and goes from there.</p>
  
  <p>It all works fine and dandy until I split it to a new thread. This error happens</p>
  
  <blockquote>
    <p>Attempted to read or write protected
    memory. This is often an indication
    that other memory is corrupt.</p>
  </blockquote>
  
  <p>when executing this code on the object in the new thread:</p>
  
  <pre><code>    protected object GetPropertyValue(object obj, string PropertyName)
      {
          return obj.GetType().InvokeMember(PropertyName, BindingFlags.GetProperty, null, obj, new object[] { });
      }
  </code></pre>
  
  <p>The above is trying to access a property on a COM object. Changing the function to 'public' doesn't affect it. The code works just fine however if I'm using just one thread.</p>
  
  <p>What's happening is clear: The new thread does not have access to the variable in the EXE. How can I fix this? Not using a thread is not a viable option.</p>
  
  <p>Appreciate any help</p>