Bug 40917 - When item is accessed from Queue it is always null on iOS
Summary: When item is accessed from Queue it is always null on iOS
Alias: None
Product: iOS
Classification: Xamarin
Component: BCL Class Libraries ()
Version: XI 9.6 (iOS 9.3)
Hardware: PC Windows
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2016-05-05 19:05 UTC by Ivan Icin
Modified: 2016-05-09 17:37 UTC (History)
4 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 Developer Community or GitHub 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 Ivan Icin 2016-05-05 19:05:58 UTC
When I add an item to Queue<T> it is null however I access it e.g. Queue.Dequeue().

I can see the item in the Queue in the debugger but when it is accessed I get null as explained above. Even if I do something like turning the queue into the list and accessing the item it ends up the same. Also the app seem to freeze in the next line after that, though I don't see anything in the output window.

When I change the app to use List<T> instead of Queue<T> it works correctly. And Queue<T> code worked perfectly on the UWP app. So there is some problem in MonoTouch.
Comment 1 Sebastien Pouliot 2016-05-05 21:31:24 UTC
Our unit tests does not show this behaviour. Can you please attach a test case so we can see how it's used and the exact build options that were used ? Thanks!
Comment 2 Ivan Icin 2016-05-08 13:49:27 UTC
I'll see if I can make some testcase. Unfortunately this is a piece of software that has several tens of thousands of lines and it is hard to isolate some testcase from it.

If you can't see the behavior in the simple test case that you have tried, my guess would be that the next thing to test is to Enqueue one item on one thread and Dequeue it later from another thread, that's what my app is doing. If you still can't see it then there are some gremlins in my room :).

As I did some workaround by emulating Enqueue and Dequeue with List, I can't spend too much time trying to make a test case for the bug, but I'm still willing to help if I can.
Comment 3 Sebastien Pouliot 2016-05-09 13:53:33 UTC
If it's used from multiple threads then it's even more important for bus to see the code as not every usage of a Queue<T> is thread safe [1].

[1] https://msdn.microsoft.com/en-us/library/7977ey2c(v=vs.110).aspx

Note that the version of XI you're using, 9.6 (aka cycle 6), is using MS reference source code for the Queue<T> implementation, so the above warning fully applies.

As an alternative you might want to switch to ConcurrentQueue<T> to see if it solve your issue.
Comment 4 Ivan Icin 2016-05-09 17:37:05 UTC
I believe you are right. It works on UWP, but I guess it is just by chance and may break in some future release, so I'll switch to the ConcurrentQueue.