Reporter | Yuri Astrakhan (yurik) |
---|---|
Created | Feb 19, 2009 4:28:07 AM |
Updated | Apr 26, 2018 12:55:40 PM |
Resolved | Apr 26, 2018 12:55:40 PM |
Subsystem | Code Style - Cleanup |
Assignee | Eugene Strizhok (Eugene.Strizhok) |
Priority | Major |
State | Fixed |
Type | Bug |
Fix version | 9.0 |
Affected versions | No Affected versions |
Fixed In Version ReSharper | Undefined |
VsVersion | All Versions |
.Net by default sets the struct layout to sequential, and a number of binary serialization scenarios use it. The fields in structs should never be sorted as doing so messes up such serializations.
Examples of code that would be messed up.
var gch = GCHandle.Alloc(data, GCHandleType.Pinned);
(T) Marshal.PtrToStructure(gch.AddrOfPinnedObject(), typeof (T));
–
fixed (byte* p = &data[0])
return (T) Marshal.PtrToStructure(new IntPtr(p), typeof (T));
–
fixed (byte* packet = &data[0])
return (Packet) packet;
etc.
In order words, any code that would use my article http://www.codeproject.com/KB/cs/ReadingStructuresEmit.aspx
Examples of code that would be messed up.
var gch = GCHandle.Alloc(data, GCHandleType.Pinned);
(T) Marshal.PtrToStructure(gch.AddrOfPinnedObject(), typeof (T));
–
fixed (byte* p = &data[0])
return (T) Marshal.PtrToStructure(new IntPtr(p), typeof (T));
–
fixed (byte* packet = &data[0])
return (Packet) packet;
etc.
In order words, any code that would use my article http://www.codeproject.com/KB/cs/ReadingStructuresEmit.aspx