Explicit structure layout and constructor #7261
-
Please consider this C# code:
It results in the following error message:
Am I wrong in expecting one of the following things to be true:
Please advise. |
Beta Was this translation helpful? Give feedback.
Answered by
huoyaoyuan
Jun 8, 2023
Replies: 1 comment 5 replies
-
The compiler doesn't know anything about FieldOffset or take it into account at all. To silence this error/warning (depends on which C# version you're in), I would suggest |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use
Unsafe.SkipInit(out this)
to skip the check.FieldOffset is often handled by the runtime. Only one value will be stored.
BTW your P/Invoke code is wrong, because SIGNER_FILE_INFO and SIGNER_BLOB_INFO should be pointers instead of nested structs. I'd suggest using CsWin32 to auto generate P/Invoke code for correctness.