Bug 1144 - Linked away exception on AsyncWaitHandle.WaitOne() on device, not simulator
Summary: Linked away exception on AsyncWaitHandle.WaitOne() on device, not simulator
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 4.x
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
Depends on:
Reported: 2011-09-29 14:44 UTC by Johan Wiersma
Modified: 2011-10-06 08:02 UTC (History)
2 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 Johan Wiersma 2011-09-29 14:44:17 UTC
A call to System.Threading.AsyncWaitHandle.WaitOne(...) fails on the device with a "linked away" exception. This happens on the physical device (iPad2, iPhone 3G) but in the simulator(s) it works fine.

Exception message:
System.NotSupportedException: Linked away at System.Threading.WaitHandle.WaitOne (Int32 millisecondsTimeout, Boolean exitContext) [0x00000]

code snippet:

Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); 
IAsyncResult ias = socket.BeginConnect(ip, 4201, null, null);
ias.AsyncWaitHandle.WaitOne(15, true)) --> causes exception

Monotouch 4.2.2 / MonoDevelop 2.6
Comment 1 Sebastien Pouliot 2011-09-29 15:33:11 UTC
Downgrading severity since there's a workaround available by using "Don't link" in the project's options

note: it should also be possible to use "Link SDK assemblies" and specify "--linkskip=mscorlib" in the "extra mtouch arguments" if a release is required (and/or the app size become a huge nuisance).
Comment 2 Sebastien Pouliot 2011-09-29 17:08:09 UTC
Using either:

ias.AsyncWaitHandle.WaitOne(15, false);



would work without issue. However the part where 'exitContext' is true is being linked away.
Comment 3 Sebastien Pouliot 2011-09-29 17:22:01 UTC
The above meant that you can resume using "Link SDK assemblies" unless you really need this to be true - but I'm not sure it really works on MonoTouch applications. Where you using 'true' for a specific reason ?

ref: http://msdn.microsoft.com/en-us/library/kzy257t0.aspx
Comment 4 Johan Wiersma 2011-09-29 18:33:06 UTC
There was no specific reason for using the exitcontext parameter for my purposes, it can be false or ommitted as far as i'm concerned.
Comment 5 Sebastien Pouliot 2011-09-29 19:10:33 UTC
Thanks again for the confirmation. 

I'll either remove the API or make it clear that that option cannot be used with MonoTouch.
Comment 6 Sebastien Pouliot 2011-10-06 08:02:16 UTC
Fixed in 2ce9fc1b0e2afde3101537a27ee367683f1882af (master), mono-2-10 and mobile-master.

MonoTouch will always throw a NotSupportedException when emitContext is set to true (for consistency) for linked, or unlinked, applications. 

Thanks for the report / test case!