Description
Description
Given a .NET 8 COM server and a Python 3.11 client and the following method signature:
void MyComVisibleMethod(object[] arg1, object[] arg2)
If you call the method with None (null) as one of the arguments, the python client receives a "The parameter is incorrect" exception.
In similar vein, when setting a string property to None the client receives a "No such interface supported" exception.
Reproduction Steps
Minimal repro can be found here: https://github.com/mlessmann/ComMarshalingRepro
Please follow the Readme.md there.
Expected behavior
No exception occurs. The None (null) value arrives at the COM server.
Actual behavior
Method with object[] parameter:
(-2147024809, 'The parameter is incorrect.', (0, None, 'Specified OLE variant is invalid.', None, 0, -2147024809), None)
String property setter:
-2147467262, 'No such interface supported', (0, 'System.Private.CoreLib', 'OleAut reported a type mismatch.', None, 0, -2147467262), None)
Regression?
Worked as expected in .NET Framework 4.8. Repro contains this variant as well.
Known Workarounds
No workarounds known.
Configuration
.NET SDK 8.0.101
.NET Runtime 8.0.1
Windows 11 22H2 x64
Python 3.11 (may also apply to other python versions)
Other information
Root cause seems to be in DispatchInfo::InvokeMemberWorker() and DispParamArrayMarshaler::MarshalNativeToManaged().
Depending on the client the null value arrives either as a VARIANT of VT-type 0x1 or 0x200C (array of variant), both with a value of null.
In the former case the value is rejected in this if-statement.
In the latter case the SAFEARRAY is retrieved from the variant, but is subsequently checked for null. In the null case the method simply returns without having written the out parameter. The caller doesn't check this and tries to write the result of the previous method argument to the result array. Depending on the method signature this can lead to the first argument's value being duplicated in the second argument.
Metadata
Metadata
Assignees
Type
Projects
Status