Reputation: 2224
Ok, I am calling an interop dll which I have no access to. Here is the pseudo code:
dynamic myVariable = null;
firstInteropMethod(ref myVariable);
secondInteropMethod(myVariable); //Not by ref
The method signatures for the two methods are
firstInteropMethod(ref object someObject);
secondInteropMethod(object someObject);
The expected value is a double array of the definition
double[,]
Now the fun part. My original code gets the wrong results but no error. However, this code:
firstInteropMethod(ref myVariable);
secondInteropMethod((double[,]) myVariable);
Gives the expected results.
Using watches and type of statements I have determined that nothing changes between the two calls so what gives? Why would there be a difference and what would that difference be?
Upvotes: 7
Views: 3886
Reputation: 4993
This MSDN article on dynamic explains why casting is needed for COM Interop when operations declare the parameter type as object
and indicates that using the /link:filelist
compiler option will allow you to define the COM method signatures as dynamic as well.
Upvotes: 5