Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic vs Typed produces strange results
    primarykey
    data
    text
    <p>I have SAP RPC OCX control that I'd like to use. In C# 4 following code works fine:</p> <pre><code>System.Type t = System.Type.GetTypeFromProgID("SAP.Functions", true); dynamic fc = System.Activator.CreateInstance(t, false); dynamic connection = fc.Connection; connection.System = ""; </code></pre> <p>Following code does NOT work (even though connection is NOT null)</p> <pre><code>System.Type t = System.Type.GetTypeFromProgID("SAP.Functions", true); dynamic fc = System.Activator.CreateInstance(t, false); var connection = fc.Connection as SAPLogonCtrl.Connection connection.System = ""; </code></pre> <p>Following error is thrown: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."</p> <p>The most bizarre fact is this though:</p> <pre><code>System.Type t = System.Type.GetTypeFromProgID("SAP.Functions", true); dynamic fc = System.Activator.CreateInstance(t, false); dynamic c1 = fc.Connection; var c2 = fc.Connection as SAPLogonCtrl.Connection; if (c1 == c2) c2.System = ""; </code></pre> <p>Last line is executed and throws the same exception!!! Replace c2 with c1 works as expected...</p> <p>I feel I am missing something trivial and yet I am at a complete loss... Please help?</p> <p>Additional info: Changing from:</p> <pre><code>dynamic fc = System.Activator.CreateInstance(t, false); </code></pre> <p>to:</p> <pre><code>var fc = System.Activator.CreateInstance(t, false) as SAPFunctionsOCX.SAPFunctions; </code></pre> <p>Makes no difference. c1 still works and c2 still does not.</p> <p>Additional info #2: Changing properties on FC itself also works in both cases.</p>
    singulars
    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.
 

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