Bug 14069 - NullReferenceException thrown when calling a callback from an Interop (signature decorated with InAttribute)
Summary: NullReferenceException thrown when calling a callback from an Interop (signat...
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: Interop ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-08-19 07:57 UTC by yoram.harmelin
Modified: 2013-09-09 09:41 UTC (History)
3 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-08-19 07:57:47 UTC
Scenario in which the bug occur:
- ProgramA (.NET, C#) call LibraryA (C) through interop
- The function called in LibraryA takes a callback argument; the passed callback is defined in ProgramA
- One of the parameter sent by LibraryA to the callback is a `ref struct`
- The natively allocated memory backing one of the callback parameter is coming from a memory mapped region with the read only bit set

As the parameter of the callback is defined with [In, Out] (due to the ref keyword), this lead to a first Exception being thrown.

Applying only the [InAttribute] on the callback parameter solved the issue for the native .NET framework (successful execution).
However, a NullReferenceException occurs when running with Mono.

The bug can be seen here: https://github.com/libgit2/libgit2sharp/pull/487
The failing CI build (ran with Mono 2.10) can be seen here: https://travis-ci.org/libgit2/libgit2sharp/builds/10357001
Comment 1 Zoltan Varga 2013-09-05 12:15:12 UTC
If the problem was that mono tried to copy data back to the native representation even without an [Out] attribute, that is now fixed in mono master e682eceec3066a26afff333a7c1eb0e977ce7caa.
Comment 2 yoram.harmelin 2013-09-09 09:41:30 UTC
Thanks!