Bug 49813 - Crash when using webView:decidePolicyForNavigationResponse:decisionHandler
Summary: Crash when using webView:decidePolicyForNavigationResponse:decisionHandler
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 10.2 (iOS 10.1)
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2016-12-13 13:26 UTC by Suat Korkmaz
Modified: 2016-12-16 21:12 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 Suat Korkmaz 2016-12-13 13:26:00 UTC
ObjCRuntime.RuntimeException: Unable to locate the block to delegate conversion method for the method EBADersIOS.NavigationDelegate.ForNavigationResponseDecidePolicy's parameter #3.

        public void ForNavigationResponseDecidePolicy(WKWebView webView, WKNavigationResponse navigationResponse, Action<WKNavigationResponsePolicy> decisionHandler)
            NSHttpUrlResponse response = (NSHttpUrlResponse)navigationResponse.Response;
            NSHttpCookie[] cookies = NSHttpCookie.CookiesWithResponseHeaderFields(response.AllHeaderFields, response.Url);
            foreach (NSHttpCookie cookie in cookies)

Comment 1 Manuel de la Peña [MSFT] 2016-12-16 15:32:44 UTC
@Suat can you please include your full build logs, crash reports (if any), 
test case (to reproduce) and all version informations.

The easiest way to get exact version information is to use the 
"Xamarin Studio" menu, "About Xamarin Studio" item, "Show Details" 
button and copy/paste the version informations (you can use the 
"Copy Information" button).
Comment 2 Sebastien Pouliot 2016-12-16 21:12:30 UTC
@Suat, this is normal. If you manually/directly export methods, using an [Export] attribute, then you are responsable to include any needed marshalling code, e.g. to turn a C# delegate into a ObjC block.

If you look (assembly browser) how Xamarin.iOS.dll define it's own binding you'll see the last parameter had a [BlockProxy] attribute, which points to extra code...

You _could_ do the same but this is not easy and not something we recommend. You can avoid doing this using one of the two following patterns:

1. Subclass the WKNavigationDelegate (model) class, and override the DecidePolicy member, see http://stackoverflow.com/a/36559932/220643

2. if you cannot subclass then have your existing type implement the `IWKNavigationDelegate` interface and add your method with this signature

> public void DecidePolicy(WKWebView webView, WKNavigationAction navigationAction, Action<WKNavigationActionPolicy> decisionHandler)
> {
>    // your code
> }

This will _link_ your method with the (complete) binding of the ObjC protocol - and XI runtime will know it has to marshal the C3 delegate into a block.