I got an intermittent ArgumentNullException I can't understand.
the code looks something like
COMRow row = GetCOMRow();
DoSomething1(row);
DoSomething2(row);
DoSomething3(row);
...
// DoSomething methods all look like this:
void DoSomethingX(ICOMRow row)
{
if (row == null)
throw new ArgumentNullException(nameof(row));
...
}
// the com interface
[ComImport]
[Guid("...")]
[TypeLibType(TypeLibTypeFlags.FDual | TypeLibTypeFlags.FNonExtensible | TypeLibTypeFlags.FDispatchable)]
[SuppressUnmanagedCodeSecurity]
public interface ICOMRow { ... }
[ComImport]
[Guid("...")]
[CoClass(typeof(COMRowClass))]
public interface COMRow : ICOMRow { }
The stack trace says ArgumentNullException happens in DoSomething3!
How can the row variable be null in DoSomething3 when it wasn't in DoSomething2?
There is an implicit cast from COMRow to ICOMRow in the call. Will this lead to a COM QueryInterface which fails for some reason and silently returns null?
The COM object can sometimes be unstable (COMException) so I understand QueryInterface can fail but want to learn if that is happening here or if I need to look elsewhere.