Skip to content

Fix NullReferenceException in friendly overloads of COM methods with optional pointer parameters#1109

Merged
AArnott merged 5 commits intomainfrom
fix1081
Jan 10, 2024
Merged

Fix NullReferenceException in friendly overloads of COM methods with optional pointer parameters#1109
AArnott merged 5 commits intomainfrom
fix1081

Conversation

@AArnott
Copy link
Copy Markdown
Member

@AArnott AArnott commented Jan 10, 2024

Optional parameters cannot be expressed with the ref modifier on COM methods in order to avoid a pointer type. Doing so disallows the possibility of passing in null. Even Unsafe.NullRef<T>() does not work because the .NET interop layer throws NullReferenceException when that's done.

Instead, we leave it as a pointer type.

An alternative to this may be to declare the parameter as an array that allows null or exactly 1 element. But the API wouldn't describe itself very well, and enforcement wouldn't exist, leading to possible runtime failures.

Fixes #1081


AI generated summary

This pull request includes a significant number of changes to various files in the codebase. The most important changes include adding a new enum to categorize different elements being generated in Generator.cs, modifying methods in Generator.Com.cs to generate appropriate type syntax based on the generating element, and adding a new test method in COMTests.cs to verify the declaration of COM methods.

Main interface changes:

Other important changes:

Please note that due to the large number of changes and limited space, only a subset of the changes are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Calling IMMDevice.Activate() results in a NullReferenceException

1 participant