Bug 59279 - WKWebView with DidReceiveAuthenticationChallenge crashes on iOS 11
Summary: WKWebView with DidReceiveAuthenticationChallenge crashes on iOS 11
Status: RESOLVED DUPLICATE of bug 59247
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 10.99 (xcode9)
Hardware: PC Windows
: --- major
Target Milestone: Xcode9
Assignee: Vincent Dondain [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2017-09-07 08:11 UTC by Michael Rumpler
Modified: 2017-09-12 05:26 UTC (History)
8 users (show)

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


Attachments
repro (55.77 KB, application/x-zip-compressed)
2017-09-07 08:11 UTC, Michael Rumpler
Details


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:
Status:
RESOLVED DUPLICATE of bug 59247

Description Michael Rumpler 2017-09-07 08:11:06 UTC
Created attachment 24613 [details]
repro

I use a WKWebView to connect to a web page with basic authentication. For this purpose I implemented a WKNavigationDelegate and overrode DidReceiveAuthenticationChallenge. This works perfectly on iOS 10.3, but the app crashes on iOS 11. It seems like it crashes when the method DidReceiveAuthenticationChallenge should be called.

I get this exception:

ObjCRuntime.RuntimeException: The ObjectiveC class 'WKNSURLAuthenticationChallenge' could not be registered, it does not seem to derive from any known ObjectiveC class (including NSObject).
  at Registrar.DynamicRegistrar.Lookup (System.IntPtr class, System.Boolean throw_on_error) [0x0008c] in /Users/builder/data/lanes/5024/bc9a39fc/source/xamarin-macios/src/ObjCRuntime/DynamicRegistrar.cs:951 
  at ObjCRuntime.Class.Lookup (System.IntPtr klass, System.Boolean throw_on_error) [0x00000] in /Users/builder/data/lanes/5024/bc9a39fc/source/xamarin-macios/src/ObjCRuntime/Class.cs:121 
  at ObjCRuntime.Class.Lookup (System.IntPtr klass) [0x00000] in /Users/builder/data/lanes/5024/bc9a39fc/source/xamarin-macios/src/ObjCRuntime/Class.cs:116 
  at ObjCRuntime.Runtime.GetNSObject (System.IntPtr ptr, System.Type target_type, ObjCRuntime.Runtime+MissingCtorResolution missingCtorResolution, System.Boolean evenInFinalizerQueue, System.Boolean& created) [0x0003d] in /Users/builder/data/lanes/5024/bc9a39fc/source/xamarin-macios/src/ObjCRuntime/Runtime.cs:1154 
  at ObjCRuntime.Runtime.GetNSObjectWithType (System.IntPtr ptr, System.IntPtr type_ptr, System.Boolean& created) [0x0000c] in /Users/builder/data/lanes/5024/bc9a39fc/source/xamarin-macios/src/ObjCRuntime/Runtime.cs:646 
  at ObjCRuntime.Runtime.get_nsobject_with_type (System.IntPtr obj, System.IntPtr type, System.Boolean& created, System.Int32& exception_gchandle) [0x00003] in /Users/builder/data/lanes/5024/bc9a39fc/source/xamarin-macios/runtime/Delegates.generated.cs:404 

It seems like the internal WKNSURLAuthenticationChallenge is indeed a NSProxy which is no NSObject.
See https://github.com/WebKit/webkit/blob/c637754ee7dfca6142e441d2040026903fee0c1f/Source/WebKit/UIProcess/API/Cocoa/WKNSURLAuthenticationChallenge.h#L43, https://github.com/WebKit/webkit/blob/0e70cf85f1e146fe7ae6536966655fcadc8e5fa7/Source/WebKit/Shared/Cocoa/WKObject.h#L55 and https://developer.apple.com/documentation/foundation/nsproxy

You can see the problem with the attached project. The third button opens a WKWebView with a delegate which implements DidReceiveAuthenticationChallenge. From the debug messages you can see that it does start loading the url, but it does not execute DidReceiveAuthenticationChallenge.
On a iOS 10.3 device the app works fine.

My app is already in the app store. So this is very important for me as iOS 11 is to be released next week.
Comment 1 Michael Rumpler 2017-09-07 08:51:54 UTC
If I connect to a http site without authentication, then DidReceiveAuthenticationChallenge is not called and it works. But if the target site uses https, then DidReceiveAuthenticationChallenge should be called (with authMethod=AuthenticationMethodServerTrust) and it crashes again.

This happens in iOS 11, beta 8 and 9.
Comment 2 Manuel de la Peña [MSFT] 2017-09-08 10:32:57 UTC
I can confirm and reproduce the bug. App does work with iOS 10.3 and crashes with 11.0 with the Xcode 9 branch. Here is my environment:

=== Visual Studio Community 2017 for Mac (Preview) ===

Version Preview - Internal Dogfood (7.2 build 576)
Installation UUID: 8d12e55e-3489-463f-ac52-8cb4573c5a81
Runtime:
	Mono 5.2.0.215 (d15-3/da80840) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 502000215

=== NuGet ===

Version: 4.3.0.4199

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	1.1.2
	1.0.5
	1.0.0
SDK: /usr/local/share/dotnet/sdk/1.0.4/Sdks
SDK Versions:
	1.0.4
	1.0.0-preview2-003121
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.2.0/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.5.5
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Xamarin.Android ===

Version: 7.4.0.21 (Visual Studio Community)
Android SDK: /Users/mandel/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.3   (API level 18)
		4.4   (API level 19)
		5.0   (API level 21)
		6.0   (API level 23)
		7.1   (API level 25)

SDK Tools Version: 25.2.5
SDK Platform Tools Version: 25.0.4
SDK Build Tools Version: 25.0.1

Java SDK: /usr
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Inspector ===

Version: 1.2.2
Hash: b71b035
Branch: d15-1
Build date: Fri, 21 Apr 2017 17:57:12 GMT

=== Apple Developer Tools ===

Xcode 9.0 (13238.4)
Build 9M214v

=== Xamarin.iOS ===

Version: 10.99.7.32 (Visual Studio Community)
Hash: aa6004ca
Branch: xcode9
Build date: 2017-09-07 16:10:43+0200

=== Xamarin.Mac ===

Version: 3.99.7.32 (Visual Studio Community)

=== Build Information ===

Release ID: 702000576
Git revision: e3f9469d94ad4932e083ecaa6f998865f15fa452
Build date: 2017-09-05 04:52:47-04
Xamarin addins: 088cef5814d09f9af2866d860110075e14f24435
Build lane: monodevelop-lion-dogfood-vNext

=== Operating System ===

Mac OS X 10.12.6
Darwin 16.7.0 Darwin Kernel Version 16.7.0
    Thu Jun 15 17:36:27 PDT 2017
    root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64
Comment 3 alan.grgic 2017-09-11 17:50:59 UTC
I'm also experiencing this issue. Can we expect this to be resolved in time for the iOS 11 release?
Comment 4 Alex Soto [MSFT] 2017-09-12 05:26:24 UTC
Please see bug #59247 for a workaround.

*** This bug has been marked as a duplicate of bug 59247 ***