Bug 4992 - Npgsql2.0.11 Is not working on MonoTouch
Summary: Npgsql2.0.11 Is not working on MonoTouch
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 5.3.x
Hardware: PC Mac OS
: Low normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-05-10 05:35 UTC by Mikkel Kruse Johnsen
Modified: 2012-06-06 10:31 UTC (History)
5 users (show)

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

Npgsql Test on MonoTouch NOT working (1.64 MB, application/x-bzip2)
2012-05-10 05:36 UTC, Mikkel Kruse Johnsen
Npgsql Test on MonoDroid IS working (951.82 KB, application/x-bzip2)
2012-05-10 05:37 UTC, Mikkel Kruse Johnsen

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 Mikkel Kruse Johnsen 2012-05-10 05:35:25 UTC
Compiling Npgsql2.0.11 on MonoTouch (with very few changes) always gives "Failed to establish connection to *"

Using MonoDroid and the exact same Npgsql source code it is working fine.
Comment 1 Mikkel Kruse Johnsen 2012-05-10 05:36:27 UTC
Created attachment 1845 [details]
Npgsql Test on MonoTouch NOT working
Comment 2 Mikkel Kruse Johnsen 2012-05-10 05:37:03 UTC
Created attachment 1846 [details]
Npgsql Test on MonoDroid IS working
Comment 3 Rolf Bjarne Kvinge [MSFT] 2012-05-10 06:07:19 UTC
It doesn't work because of this:


if I change NpgsqlClosedState.cs:123 to this (passing false for the second argument to WaitOne), it works:

if (!result.AsyncWaitHandle.WaitOne(context.ConnectionTimeout*1000, false))
Comment 4 Mikkel Kruse Johnsen 2012-05-10 06:17:55 UTC
Yes I can confirm that it works.

Is that a bug in Mono ?
Comment 5 Rolf Bjarne Kvinge [MSFT] 2012-05-10 06:18:13 UTC
Sebastien, it looks like you added the NotSupportedException in WaitHandle. Maybe it's better to just ignore the exitContext parameter? MSDN says: "The exitContext parameter has no effect unless the WaitOne method is called from inside a nondefault managed context."
Comment 6 Rolf Bjarne Kvinge [MSFT] 2012-05-10 06:19:00 UTC
Mikkel, right now it's a restriction in MonoTouch, but we might be able to remove that restriction.
Comment 7 Sebastien Pouliot 2012-05-10 08:03:59 UTC
Mikkel, that makes sense wrt --nolinkaway you used.

Rolf, we could set `emitContext` to false in every case (for MT). The exception was for people to review/fix their code - but sadly it looks like some libraries do not propagate the original exception to the application :-( Maybe an additional CWL that would show in the logs would serve better.
Comment 8 Mikkel Kruse Johnsen 2012-05-10 08:18:54 UTC
Yes when using Npgsql1 (Npgsql.dll) and --nolinkaway I got "exitContext == true" something.

Npgsql2 did not have that error, but failed to connect.
Comment 9 Sebastien Pouliot 2012-05-10 08:23:15 UTC
> Is that a bug in Mono ?

A bit. IMO the API (w/bool) should not have been exposed. The additional synchronization code has issues with MonoTouch (and that's why it's removed by the linker). Using --nolinkaway is a way to mitigate the issue, leading to larger binaries but without solving every issues.

It's also an issue with Npgsql. Unless there's a specific reason (and I'm not sure there is) Npgsql should be using `Wait(int)` which defaults to `false`. If only because it's far more heavyweight that it needs to be (when supported).

Also the overload with a boolean parameter is also not part of the Portable Class Library profiles (1-4) so it limits Npgsql availability to other profiles (e.g. xbox) but there could be many other limitations beside that one.

I'm c.c.ing Francisco Figueiredo Jr. which maintains Npgsql to see if he can (also) fix the Npgsql code so this would work on older, existing, MonoTouch releases (for other interested peoples).
Comment 10 Rolf Bjarne Kvinge [MSFT] 2012-06-01 08:05:11 UTC
Upstream bug has been filed: http://pgfoundry.org/tracker/index.php?func=detail&aid=1011200&group_id=1000140&atid=590
Comment 11 Francisco Figueiredo Jr. 2012-06-04 14:17:58 UTC

I'll make the change. From what I can see from this discussion and from the documentation, changing it to false won't have any impact to Npgsql and will give the added bonus of working on MonoTouch without any issues.

Thanks for bug report.
Comment 12 Francisco Figueiredo Jr. 2012-06-06 10:31:38 UTC
Fixed in Npgsql main repository. New Npgsql releases will work with Monotouch out of the box.

Thanks for reporting.