Dynamic keyword, C # and Interop?

Ok, I call the dll interop, which I do not have access to. Here is the pseudo code:

dynamic myVariable = null; firstInteropMethod(ref myVariable); secondInteropMethod(myVariable); //Not by ref 

Method signatures for two methods:

 firstInteropMethod(ref object someObject); secondInteropMethod(object someObject); 

The expected value is a double definition array.

 double[,] 

Now the fun part. My source code gets the wrong results, but no errors. However, this code:

 firstInteropMethod(ref myVariable); secondInteropMethod((double[,]) myVariable); 

It gives the expected results.

Using the clock and application types, I determined that nothing changes between the two calls, what gives? Why would there be a difference and what is the difference?

+6
source share
1 answer

This MSDN article on dynamics explains why casting is necessary for COM Interop when operations declare a parameter type as object and indicate that using the /link:filelist compiler parameter will also allow you to define COM method signatures as dynamic.

+4
source

Source: https://habr.com/ru/post/888408/


All Articles