Bug 57172 - Marshalling structures containing objects doesn't work with LayoutKind.Explicit
Summary: Marshalling structures containing objects doesn't work with LayoutKind.Explicit
Status: CONFIRMED
Alias: None
Product: Runtime
Classification: Mono
Component: Interop (show other bugs)
Version: 5.0 (2017-02)
Hardware: PC Linux
: --- normal
Target Milestone: Future Cycle (TBD)
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-06-06 09:25 UTC by tmucbvest
Modified: 2017-07-10 14:56 UTC (History)
3 users (show)

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


Attachments
Test case for marshalling structure using LayoutKind.Explicit (2.46 KB, text/plain)
2017-06-06 09:25 UTC, tmucbvest
Details
mono -trace=all bug.exe (180.39 KB, text/plain)
2017-07-08 01:41 UTC, tmucbvest
Details

Description tmucbvest 2017-06-06 09:25:48 UTC
Created attachment 22710 [details]
Test case for marshalling structure using LayoutKind.Explicit

I use Mono 5.0.1

The test case compiles on Win/.net and Linux/Mono.
It runs OK under Windows.net but it crashes under Mono.

The compiled exe using VS2017 crashes when it is run under Mono.
The compiled exe using csc(Roslyn complier) crashes when it is run under Windows/.net, so probably
it is not just a runtime problem , but also a compiler problem.
Comment 1 Ludovic Henry 2017-07-03 21:37:07 UTC
Hello,

I tried with following version 

> Mono JIT compiler version 5.0.1.1 (2017-02/5077205 Thu May 18 16:11:37 EDT 2017)
> Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
> 	TLS:           normal
> 	SIGSEGV:       altstack
> 	Notification:  kqueue
> 	Architecture:  x86
> 	Disabled:      none
> 	Misc:          softdebug
> 	LLVM:          yes(3.6.0svn-mono-master/8b1520c)
> 	GC:            sgen (concurrent by default)

The following command works fine without crashing:

> mcs -debug bug57172.cs && mono --debug bug57172.exe

Could you please provide more information on how you run the provided sample?

Thank you,
Ludovic
Comment 2 tmucbvest 2017-07-08 01:40:39 UTC
I am attaching traceall.log


kornos@ubuntu:~/projects/STEAM/bin/sources/bugs$ mono --trace=all  bug.exe > traceall.log

Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
  at explicit1.Program.RunMe () [0x0003e] in <52b7e6fd4abc44cba8dcdffb26b13a36>:0 
  at explicit1.trigger.Main (System.String[] args) [0x00007] in <52b7e6fd4abc44cba8dcdffb26b13a36>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
  at explicit1.Program.RunMe () [0x0003e] in <52b7e6fd4abc44cba8dcdffb26b13a36>:0 
  at explicit1.trigger.Main (System.String[] args) [0x00007] in <52b7e6fd4abc44cba8dcdffb26b13a36>:0
Comment 3 tmucbvest 2017-07-08 01:41:12 UTC
Created attachment 23418 [details]
mono -trace=all bug.exe
Comment 4 tmucbvest 2017-07-08 01:45:14 UTC
xxxxx@ubuntu:~/projects/STEAM/bin/sources/bugs$ mono -V
Mono JIT compiler version 5.0.1.1 (2017-02/5077205 Thu May 25 09:19:30 UTC 2017)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           __thread
	SIGSEGV:       altstack
	Notifications: epoll
	Architecture:  amd64
	Disabled:      none
	Misc:          softdebug 
	LLVM:          supported, not enabled.
	GC:            sgen (concurrent by default)
Comment 5 Ludovic Henry 2017-07-10 14:56:33 UTC
I can confirm I can reproduce that on Ubuntu 16.04 64bits with following version of mono:

> Mono JIT compiler version 5.0.1.1 (2017-02/5077205 Thu May 25 09:19:18 UTC 2017)
> Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
> 	TLS:           __thread
> 	SIGSEGV:       altstack
> 	Notifications: epoll
> 	Architecture:  amd64
> 	Disabled:      none
> 	Misc:          softdebug
> 	LLVM:          supported, not enabled.
> 	GC:            sgen (concurrent by default)

I cannot reproduce on Ubuntu 16.04 32bits, nor on OSX 64bits.

The command to reproduce is the following:

> mcs -debug bug57172.cs && mono bug57172.exe

The expected output is:

> NtHeaders[0]= A

The observed output is:

> Unhandled Exception:
> System.NullReferenceException: Object reference not set to an instance of an object
>   at explicit1.Program.RunMe () [0x0003e] in <63ff8b566b2347aeb245212c0394ffa9>:0
>   at explicit1.trigger.Main (System.String[] args) [0x00007] in <63ff8b566b2347aeb245212c0394ffa9>:0
> [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
>   at explicit1.Program.RunMe () [0x0003e] in <63ff8b566b2347aeb245212c0394ffa9>:0
>   at explicit1.trigger.Main (System.String[] args) [0x00007] in <63ff8b566b2347aeb245212c0394ffa9>:0

Note You need to log in before you can comment on or make changes to this bug.