Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
I have some issues when using function compiled with async+generics.
The attached code, when compiled with mono compiler, works fine (TestMonoAsyncGenerics-MCS.exe).
However, when compiled with MS compiler, it doesn't work with mono VM (TestMonoAsyncGenerics-CSC.exe)
Generated JIT code is invalid (parameters are not copied properly into the async generic struct -- trying to use them result in a crash because objects that should be valid are null). Attached code show this issue in AsyncWithAwait.
On top of this, if the async method has no await, it will generates an exception.
Attached code show this issue in AsyncNoAwait. I suppose this is related to previous bug.
Expected output, when running TestMonoAsyncGenerics-CSC.exe (works fine with MS.NET VM)
But I get this with mono:
System.NullReferenceException: Object reference not set to an instance of an object
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[System.Object].SetResult (System.Object result) [0x00000] in <filename unknown>:0
Of course I just show the issue with a int, but if it's a pointer it will be null and crash when using it as well.
Reproduced issue with both freebsd x64 and windows official beta package (2.11.4).
Created attachment 2618 [details]
TestMonoAsyncGenerics.cs reproducing issue + generated MCS and CSC executables (if needed)
This is probably due to the differences between the class library support the generated async code depends on.
Just so you know, when I investigated I had more the feeling about codegen issues at assembly level (parameters get shifted/lost in the stack).
Even if class library was bad, the point is it was trying to dereference a pointer at a location where there was nothing (a variable supposed to be on the stack but it was not). Except if unsafe code in that class library is wrong, it should not be possible, right?
You can try the behavior by replacing the int with a class and trying to access it (I did a showcase with a int, but with a class it will just end up pointing on invalid memory).
There is an AsyncTaskMethodBuilder<T> struct on the stack, and the code inside SetResult () tries to
do this call:
if (!task.TrySetResult (null))
The 'task' field is null, which causes the NullReferenceException.
Ha yes, sorry, I thought about the first issue (display 0 instead of 32, or crash if class).
About the second issue (with no real async), it's most likely class library as you said.
Zolta, it's generic sharing bug.
It looks like it is, it works with -O=-gshared.
Created simpler test case as 7574
*** This bug has been marked as a duplicate of bug 7574 ***