Bug 11417 - Marshal.PtrToStructure behaves differently on Windows and Linux
Summary: Marshal.PtrToStructure behaves differently on Windows and Linux
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: 2.10.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-03-26 07:59 UTC by yoram.harmelin
Modified: 2013-03-26 17:09 UTC (History)
4 users (show)

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

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:
Status:
RESOLVED FIXED

Description yoram.harmelin 2013-03-26 07:59:08 UTC
[Fact]
public void Test()
{
    Assert.Null(Marshal.PtrToStructure(IntPtr.Zero, typeof(string)));
}

[Fact]
public void Test2()
{
    Assert.Null(Marshal.PtrToStructure((IntPtr)null, typeof(string)));
}

Those two tests pass on Windows 7 (x86 and amd64) but fail on Mono with the following call stack:
LibGit2Sharp.Tests.MergeFixture.Test: System.ArgumentNullException : Argument cannot be null.
Parameter name: src
  at (wrapper managed-to-native) System.Runtime.InteropServices.Marshal:PtrToStructure (intptr,System.Type)
  at LibGit2Sharp.Tests.MergeFixture.Test () [0x00000] in <filename unknown>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 

LibGit2Sharp.Tests.MergeFixture.Test2: System.ArgumentNullException : Argument cannot be null.
Parameter name: src
  at (wrapper managed-to-native) System.Runtime.InteropServices.Marshal:PtrToStructure (intptr,System.Type)
  at LibGit2Sharp.Tests.MergeFixture.Test2 () [0x00000] in <filename unknown>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
Comment 1 Zoltan Varga 2013-03-26 15:01:02 UTC
Fixed in master/2.10.
Comment 2 yoram.harmelin 2013-03-26 16:51:44 UTC
That was fast! Thanks!
Comment 3 emeric.fermas 2013-03-26 17:09:32 UTC
<3