Bug 11624 - Native to managed callbacks cannot call Assembly.GetExecutingAssembly()
Summary: Native to managed callbacks cannot call Assembly.GetExecutingAssembly()
Alias: None
Product: Runtime
Classification: Mono
Component: Reflection ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2013-04-05 14:46 UTC by bfhben
Modified: 2013-04-06 04:10 UTC (History)
3 users (show)

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:

Description bfhben 2013-04-05 14:46:22 UTC
When embedding Mono if Assembly.GetExecutingAssembly() is called in a native to managed callback, eg. through a delegate passed through a pinvoke to native, then the application will crash. This appears to be an issue with mono_stack_walk_no_il in icall.c at line 4856, where dest is still NULL, causing an exception. This can be avoided in personally written code, however in places the CLR calls it, for example https://github.com/mono/mono/blob/8752d92528a1d77d71d9bc7882b04df64e40c452/mcs/class/corlib/System.Text/Encoding.cs at line 462. This causes issues with functions that should be trivial such as Console.SetOut(). This same bug also appears to be related to https://bugzilla.xamarin.com/show_bug.cgi?id=9365 and in my experience both occur at the same time. In my code, my Main function can be debugged, but the callbacks cannot.

Repro can be found at https://bitbucket.org/ben1066/embedded-mono-repro/src
Comment 1 Zoltan Varga 2013-04-06 04:10:12 UTC
Fixed in master/2.10 by: