Marshalling IntPtrs within structs in C#
问题 I intend to model a C# class for parsing custom protocol data I receive as a raw buffer. The buffer is already at hand as a byte array. This parser has to cope with varying field layouts, hence some of the protocol elements are IntPtrs. When I try to access a pointer within a struct after mapping the raw buffer into it, I run into an access violation. I made up a simple example which shows the crucial part: namespace CS_StructMarshalling { class Packet { public PacketStruct Fields;