-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Remove suggestion to consider using Marshal.SizeOf. #33725
Conversation
Where in the docs is the difference between the two explained and how to choose which one? |
In the Remarks:
Unsafe.SizeOf unfortunately is relatively new, and the docs aren't as baked: https://docs.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.unsafe.sizeof In general, my understanding is:
A concrete example of this is I was also considering dropping the suggestion all together. And simply saying |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the APIs are too new to fully document, they're far too new to suggest in a compiler message.
Before adding this I think we need public documentation on how these APIs work, what's the difference between them, and when to choose one over the other.
@agocke - would you approve of just dropping the suggestions altogether?
|
We've had that message for years and I haven't seen a lot of complaints about it, so no. |
The message is generally misleading and is leading users towards a pit-of-failure because it impliesthat Just searching for If you are interested in the differences:
|
If Unsafe.Sizeof literally calls sizeof I would imagine it's the correct error message. However the message as it currently stands is pointing people towards an incorrect replacement, so the suggestion should almost certainly be removed IMO. |
I did as @tannergooding suggested and looked at some of the Stack Overflow suggestions. It does seem like people can be confused about this. Given that, I'll reverse my position and support deleting it. |
Marshal.SizeOf is not a direct replacement for `sizeof`. Fix dotnet#26513
Thanks for the discussion everyone. I've changed it to remove the suggestions altogether. And I've updated the .xlf files to make CI happy. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
CC. @tmeschter on the xlf changes. |
@tannergooding Right now I only care about .xlf changes if you plan on trying to get this into 16.0. If this is for 16.1 then I have no concerns. |
Marshal.SizeOf is not a direct replacement for
sizeof
.Fix #26513