Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Although it looks like you're doing the same thing both times, it's actually completely different: In the first code example:</p> <pre><code>dynamic connection = fc.Connection; connection.System = ""; </code></pre> <p>what happens is you get <code>fc.Connection</code>, and then invoke the <code>System =</code> property setter using <code>dynamic</code>. The dynamic language runtime goes off and queries the COM interfaces, and invokes a particular method on a particular COM interface. You can't actually see what interface or method it's using from the C# side of things.</p> <p>In the second example (I've replaced the <code>var</code> to make things more clear):</p> <pre><code>SAPLogonCtrl.Connection connection = fc.Connection as SAPLogonCtrl.Connection connection.System = ""; </code></pre> <p>what happens is you get <code>fc.Connection</code>, and then cast it to <code>SAPLogonCtrl.Connection</code>. You then try and call <code>SAPLogonCtrl.Connection.System =</code> and then it fails. </p> <p>I suspect that it's failing because the object is not actually an instance of <code>SAPLogonCtrl.Connection</code> but it may be a proxy or some other object.</p> <p>Most COM interop is split into an interface (there's most likely an <code>SAPLogonCtrl.IConnection</code>) and a class. When calling methods, you usually need to call <em>through the interface</em>. The <code>dynamic</code> code will be doing it all for you behind the scenes.</p> <p>You could try searching for the interface, and calling using that. If it ends up that <code>SAPLogonCtrl.IConnection</code> exists, the solution <em>may</em> be as follows.</p> <pre><code>var connection = fc.Connection as SAPLogonCtrl.IConnection // note the I! connection.System = ""; </code></pre> <p>At any rate, remember to call through the interface when dealing with COM interop</p>
    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.
    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