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 ArrayTypeMismatchException on Android #879

Merged
merged 1 commit into from
Jan 9, 2023
Merged

Conversation

AArnott
Copy link
Member

@AArnott AArnott commented Jan 7, 2023

.NET arrays are covariant, so a string[] can masquerade as an object[]. But apparently object[].AsSpan will fail on such a masquerading array, presumably because a Span<object> would allow an object to be written with no further type checking. But ReadOnlySpan<object> is safe over a string[], presumably because it is read only so the type incompatibility is of no concern.

In mono, our ParameterInfo[] array is actually an array of a derived type, so it throws. By creating a ReadOnlySpan<ParameterInfo> instead of a Span<ParameterInfo>, we avoid the exception.

Fixes #860

@AArnott AArnott added this to the v2.15 milestone Jan 7, 2023
@AArnott AArnott requested a review from javierdlg January 7, 2023 00:45
@AArnott AArnott enabled auto-merge January 9, 2023 16:31
@AArnott AArnott merged commit d164d10 into microsoft:main Jan 9, 2023
@AArnott AArnott deleted the fix860 branch January 9, 2023 16:33
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.

Attempted to access an element as a type incompatible with the array.
2 participants