I have an SAP RPC OCX control that I would like to use. In C # 4, the following code works fine:
System.Type t = System.Type.GetTypeFromProgID("SAP.Functions", true); dynamic fc = System.Activator.CreateInstance(t, false); dynamic connection = fc.Connection; connection.System = "";
The following code does NOT work (although the connection is not null)
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 = "";
The following error is raised: "Attempting to read or write protected memory. This often indicates that another memory is corrupt."
The most bizarre fact is that:
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 = "";
The last line is completed and throws the same exception !!! Replace c2 with c1 works as expected ...
I feel that I am missing something trivial, and yet I am in complete loss ... Please help?
Additional information: Change:
dynamic fc = System.Activator.CreateInstance(t, false);
in
var fc = System.Activator.CreateInstance(t, false) as SAPFunctionsOCX.SAPFunctions;
Irrelevant. c1 is still working, and c2 is still not working.
Additional Information No. 2: Changing properties on the FC itself also works in both cases.
Michael feinstein
source share