Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null refs in byte array COM interop #2688

Merged
merged 7 commits into from
Mar 18, 2022

Conversation

jtschuster
Copy link
Member

Roslyn API doesn't use nullable types and will return null on properties and fields that aren't annotated with the ?. The linker assumes that fields will not be null, and those issues tend to appear most frequently with COM interop when a type doesn't have a namespace.

This fixes the null reference in a minimal repro, but there are likely more holes to address #2687.

This should fix #2686.

I wasn't sure where the test case best fits in, so it's in a separate file in the Interop test cases folder. Let me know if there's a better place for it.

There may still be holes to be addressed with Roslyn types not being
nullable.
@@ -88,11 +88,11 @@ static bool IsComInterop (ISymbol symbol)
if (typeSymbol == null)
return false;

if (typeSymbol.ContainingNamespace.Name == "System" && typeSymbol.Name == "Array") {
if (typeSymbol.ContainingNamespace?.Name == "System" && typeSymbol.Name == "Array") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have enabled nullable to catch such errors?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #2687.

@jtschuster
Copy link
Member Author

The issues were fixed by #2692, this now just adds tests.

@jtschuster jtschuster merged commit 9f2b304 into dotnet:main Mar 18, 2022
@eerhardt
Copy link
Member

For my education, how does adding new tests fix the original issue? Where is the source code change that fixed #2686?

@akoeplinger
Copy link
Member

@eerhardt see #2688 (comment)

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.

COMAnalyzer NullReferenceException in Maui Essentials
6 participants