-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Documentation for field accessors is incorrect #11059
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Thanks for finding this. Based on the code comments you are 100% correct.
|
Appears to be addressed with #10268 |
Resolved by #10268 |
Type of issue
Code doesn't work
Description
The document states that
ref
is optional for read-only field accessors. This appears to be incorrect, as anBadImageException
is thrown with "Invalid usage of UnsafeAccessorAttribute" ifref
is not specified.This line in the documentation should be changed:
"The return value for an accessor to a field can be ref if setting of the field is desired."
to indicate that
ref
is always required for both read-only and read-write access.Given this class:
According to the documentation as written this is valid:
When in fact it throws the above mentioned exception.
This code runs correctly:
Page URL
https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.unsafeaccessorattribute?view=net-9.0
Content source URL
https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Runtime.CompilerServices/UnsafeAccessorAttribute.xml
Document Version Independent Id
d8b3e8e8-a5e1-1884-99f2-678cf6a77a45
Platform Id
cbce44e6-89f0-7d37-b0fd-cb328dfbdd90
Article author
@dotnet-bot
The text was updated successfully, but these errors were encountered: