Marshalling array of structs vs classes
问题 I want to read a native struct into a C# type using Marshalling. My method to Marshal structs is like so: T ReadObject<T>(BinaryReader br) { var bytes = br.ReadBytes(Marshal.SizeOf(typeof(T))); var handle = GCHandle.Alloc(bytes, GCHandleType.Pinned); try { return (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T)); } finally { handle.Free(); } } Now this works fine in general, the problem arises with the following type: [StructLayout(LayoutKind.Sequential, Pack=1)] class SubData