Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://msdn.microsoft.com/en-us/library/d133hta4.aspx" rel="noreferrer">If you read the documentation about the method you are calling</a>, it returns</p> <blockquote> <p>A handle that must be unwrapped to access the newly created instance.</p> </blockquote> <p>Looking at the documentation of <code>ObjectHandle</code>, you simply call <a href="http://msdn.microsoft.com/en-us/library/system.runtime.remoting.objecthandle.unwrap.aspx" rel="noreferrer">Unwrap()</a> in order to get the instance of the type you are trying to create.</p> <p>So, I guess your real issue is... Why?</p> <p>This method is designed to be called in another <code>AppDomain</code>, and the handle returned back to the calling <code>AppDomain</code>, where the proxy to the instance is "unwrapped". </p> <p>What? That doesn't explain why?</p> <p>Only two types can cross an <code>AppDomain</code> barrier. Types that are serializable (of which copies are created), and types that extend <a href="http://msdn.microsoft.com/en-us/library/system.marshalbyrefobject.aspx" rel="noreferrer">MarshalByRefObject</a> (of which <em>proxies</em> are created and passed). <code>ObjectHandle</code> extends <code>MarshalByRefObject</code>, and so can cross that <code>AppDomain</code> barrier, whereas the type which they are representing may not extend MBRO <em>or</em> be serializable. This method ensures you can get that type instance across the barrier, no matter what.</p> <p>So, if you are just trying to instantiate a type, you might want to look at a different overload of CreateInstance. Or just unwrap the result.</p> <pre><code>var obj = Activator.CreateInstance("A","A.B.C") as ObjectHandle; InterfaceName in = (InterfaceName)obj.Unwrap(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload