Bug 2567 - Marshal.PtrToStructure string buffer to structure
Summary: Marshal.PtrToStructure string buffer to structure
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: 2.10.x
Hardware: All All
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2011-12-19 11:20 UTC by Guillaume Bibaut
Modified: 2012-01-14 12:59 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

PtrToStructure string buffer to structure (1.33 KB, application/octet-stream)
2011-12-19 11:21 UTC, Guillaume Bibaut

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Guillaume Bibaut 2011-12-19 11:20:31 UTC

I'm trying to use a piece of code like the following in attachment.

The (correct) result with Microsoft.Net is :

Field1: 12345678
Field2: 1234567890
Field3: 12345678901234

The result with Mono 2.10.7 (and previous version) on FreeBSD and MacOSX :

Field1: 12345678123456789012345678901234
Field2: 123456789012345678901234
Field3: 12345678901234

So, it seems that Mono is positioning the offset correctly, but does not cut the provided buffer to the correct size for each field.
Comment 1 Guillaume Bibaut 2011-12-19 11:21:18 UTC
Created attachment 1068 [details]
PtrToStructure string buffer to structure
Comment 2 Zoltan Varga 2012-01-14 12:59:03 UTC
Fixed in HEAD/2.10 branch.