Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

CA1900: Value type fields should be portable







Breaking Change

Breaking - If the field can be seen outside the assembly.

Non-breaking - If the field is not visible outside the assembly.

This rule checks that structures that are declared with explicit layout will align correctly when marshaled to unmanaged code on 64-bit operating systems. IA-64 does not allow unaligned memory accesses and the process will crash if this violation is not fixed.

Structures that have explicit layout that contains misaligned fields cause crashes on 64-bit operating systems.

All fields that are smaller than 8 bytes must have offsets that are a multiple of their size, and fields that are 8 bytes or more must have offsets that are a multiple of 8. Another solution is to use LayoutKind.Sequential instead of LayoutKind.Explicit, if reasonable.

This warning should be suppressed only if it occurs in error.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.