Bug 51294 - EVENT_KIND_ASSEMBLY_LOAD sometimes not sent
Summary: EVENT_KIND_ASSEMBLY_LOAD sometimes not sent
Alias: None
Product: Runtime
Classification: Mono
Component: Debugger ()
Version: 4.7.X
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Zoltan Varga
Depends on:
Reported: 2017-01-09 10:15 UTC by David Karlaš
Modified: 2017-05-09 06:47 UTC (History)
3 users (show)

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

repro project (260.90 KB, application/zip)
2017-01-09 10:15 UTC, David Karlaš
repro project 2 (6.10 MB, application/zip)
2017-01-11 14:44 UTC, David Karlaš

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 for Bug 51294 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description David Karlaš 2017-01-09 10:15:54 UTC
Created attachment 19128 [details]
repro project

Debugging attached project approximately 1 in 5 results in EVENT_KIND_ASSEMBLY_LOAD not being sent for assembly "xunit.assert" in "pclxUnit" domain as seen in this log output: https://gist.github.com/DavidKarlas/886d4fc3ddfe22560e99c9c442dd3368#file-load-event-not-sent-L1166-L1178
Comment 1 Zoltan Varga 2017-01-11 07:57:30 UTC
How do I run this ?
Comment 2 David Karlaš 2017-01-11 14:44:33 UTC
Created attachment 19232 [details]
repro project 2

Best way to reproduce this is to download new attachment(repro project 2)(old one had hardcoded paths) and install XS from this link(newest C9 has workaround): https://xamarin.azureedge.net/MonoDevelop/Mac/XamarinStudio-

Then open .sln inside XS and start debugging... You will have to re-run debugging multiple times until error "Debuggee returned error code ERR_UNLOADED." appears. Thats happens when runtime doesn't send ASSEMBLY_LOAD event.
Comment 3 Zoltan Varga 2017-01-16 01:10:47 UTC
It says:
Cannot open assembly '/Users/vargaz/Projects/51294/pclxUnit/packages/xunit.runner.console.2.1.0/tools/xunit.console.exe': No such file or directory.
Comment 4 David Karlaš 2017-05-08 19:39:06 UTC
Since running XS is annoying I created repro as Mono unit tests at https://github.com/mono/mono/tree/bug51294repro
Notice that some code is picked from another test and some API is changed from internal to public to be able to print Ids of mirror classes in unit tests, hence unit test will need to be polished before merging to master.

To reproduce checkout that branch, build mono, navigate to mcs/class/Mono.Debugger.Soft/ and execute `make && make run-test FIXTURE=DebuggerTests.MultiDomainLoad`
It will fail because exception `Debuggee returned error code ERR_UNLOADED.` this shouldn't happen because if runtime sent AssemblyLoad event .Location would be loaded while Assembly is loaded, hence no problem with fetching .Location after assembly is unloaded...
Comment 5 Zoltan Varga 2017-05-08 21:13:07 UTC
So here is whats happening:
* the runtime current only sends load/unload events when an assembly is really loaded/unload from the runtime, not from a domain.
* the testcase receives an assembly load event for appdomain-client.exe when its loaded into the first domain.
* it receives an unload event when its unloaded after the second domain is unloaded, but the AssemblyMirror object is per domain, so its Location field is not set, causing a protocol call which fails because the assembly is in a domain which is unloading.

Not sure how to fix this. Maybe make assembly loads/unloads per domain, but this will be an api break.
Comment 6 Jb Evain 2017-05-08 22:28:39 UTC
We had a similar issue in VSTU and we fixed it client side. What we're doing there is:

* Keep a cache of assemblies per domains
* When we get an assembly load event, we map the assembly to the domain it is loaded in (either through AssemblyMirror.Domain if the version supports it, or AssemblyMirror.GetAssemblyObject().Domain.
* We we get a domain unload event, the client considers that all assemblies in the domain will be unloaded, and we clear our cache here.
* On AssemblyUnload, if we can't get the location it means we're unloading then it means we are already in a good state.
Comment 7 David Karlaš 2017-05-09 06:47:51 UTC
@Zoltan this is what .NET(Visual Studio for Windows) outputs into debug window: https://gist.github.com/DavidKarlas/75bacacc31e44559a587eab215fe6cb5
So every assembly load/unload is reported. About API breaking... Are we talking about Profiler or SDB API? I think in both cases it should be OK to always report loads/unloads(we report unloads already)...

@Jb we could work around this but it's Runtime bug imo, hence I didn't fix it yet on IDE side...