Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.ArgumentException - Key already in the list when calling CustomWebViewNavigationDelegate in Xamarin.iOS 16.4.0.6 #18302

Closed
unamed000 opened this issue May 19, 2023 · 2 comments

Comments

@unamed000
Copy link

When we try to write our custom WkWebViewRenderer, we want to override some custom behavior from the NavigationDelegate, but we still want to to keep the default behavior from the Xamarin.Forms Delegate, that's why we will create a custom delegate that will reference to the Xamarin.Forms Delegate.

Problem is when doing this, it will cause the app to crash due to some internal code.

NOTE: We don't have the same error from the previous stable Xamarin.iOS version.

Steps to Reproduce

  1. Create a custom WebViewRenderer that inherit from WkWebViewRenderer
  2. Set this.NavigationDelegate = new WKCustomWebViewNavDelegate(this, this.NavigationDelegate)
  3. In DecidePolicy, try to call the referenced old "NavigationDelegate" (that comes from WkWebViewRenderer - CustomWebViewNavigationDelegate)
  4. Run the web view

Expected Behavior

The webview should run fine, in the end it's just calling the old "delegate", which should not causing any problem

Actual Behavior

App crash due to:

System.ArgumentException
Key already in the list

  at System.Runtime.CompilerServices.ConditionalWeakTable`2[TKey,TValue].Add (TKey key, TValue value) [0x000a8] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Runtime.CompilerServices/ConditionalWeakTable.cs:242 
  at ObjCRuntime.Runtime.ReleaseBlockWhenDelegateIsCollected (System.IntPtr block, System.Delegate delegate) [0x0001c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.4.0.6/src/Xamarin.iOS/ObjCRuntime/Runtime.cs:2049 
  at ObjCRuntime.Runtime.CreateBlockProxy (System.Reflection.MethodInfo method, System.IntPtr block) [0x0001f] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.4.0.6/src/Xamarin.iOS/ObjCRuntime/Runtime.cs:1017 
  at ObjCRuntime.Runtime.CreateBlockProxy (System.IntPtr method, System.IntPtr block) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.4.0.6/src/Xamarin.iOS/ObjCRuntime/Runtime.cs:509 
  at ObjCRuntime.Runtime.create_block_proxy (System.IntPtr method, System.IntPtr block, System.IntPtr* exception_gchandle) [0x00007] in /Users/builder/azdo/_work/1/s/xamarin-macios/runtime/Delegates.generated.cs:407 
--- End of stack trace from previous location where exception was thrown ---

  at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSend_IntPtr_IntPtr_IntPtr(intptr,intptr,intptr,intptr,intptr)
  at WebKit.WKNavigationDelegate_Extensions.DecidePolicy (WebKit.IWKNavigationDelegate This, WebKit.WKWebView webView, WebKit.WKNavigationAction navigationAction, System.Action`1[T] decisionHandler) [0x00030] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.4.0.6/src/Xamarin.iOS/WebKit/WKNavigationDelegate.g.cs:81 
  at LifeCloud.iOS.Renderers.WebViewRender+WKCustomWebViewNavDelegate.DecidePolicy (WebKit.WKWebView webView, WebKit.WKNavigationAction navigationAction, System.Action`1[T] decisionHandler) [0x00001] in /Users/huyvu/Documents/Workplace/LifeCloud/LifeCloud/LifeCloud.iOS/Renderers/WebViewRender.cs:147 
  at (wrapper managed-to-native) UIKit.UIApplication.xamarin_UIApplicationMain(int,intptr,intptr,intptr,intptr&)
  at UIKit.UIApplication.UIApplicationMain (System.Int32 argc, System.String[] argv, System.IntPtr principalClassName, System.IntPtr delegateClassName) [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.4.0.6/src/Xamarin.iOS/UIKit/UIApplication.cs:58 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00013] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.4.0.6/src/Xamarin.iOS/UIKit/UIApplication.cs:84 
  at LifeCloud.iOS.Application.Main (System.String[] args) [0x00001] in /Users/huyvu/Documents/Workplace/LifeCloud/LifeCloud/LifeCloud.iOS/Main.cs:17 

Environment

Version information
Visual Studio Community 2022 for Mac
Version 17.5.5 (build 12)
Installation UUID: 3949816b-a508-490a-9964-91c3f74c287e

Runtime
.NET 7.0.1 (64-bit)
Architecture: Arm64
Microsoft.macOS.Sdk 12.3.2372; git-rev-head:754abbf6a3563f6267e5717ae832b4ac25b1f2fb; git-branch:release/7.0.1xx-xcode13.3

Xamarin Designer
Version: 17.5.3.47
Hash: e8b5d371c3
Branch: remotes/origin/d17-5
Build date: 2023-05-12 16:19:05 UTC

Roslyn (Language Service)
4.5.0-3.23056.2+97881342e427ff5cdcba8f12b12ff8e6f3564431

NuGet
Version: 6.4.0.117

.NET SDK (Arm64)
SDK: /usr/local/share/dotnet/sdk/7.0.302/Sdks
SDK Versions:
	7.0.302
	7.0.203
	7.0.105
	7.0.100
	7.0.100-rc.1.22414.7
	6.0.408
	6.0.406
	6.0.405
	6.0.404
	6.0.403
	6.0.401
MSBuild SDKs: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks

.NET SDK (x64)
SDK Versions:
	7.0.302
	7.0.203
	6.0.408

.NET Runtime (Arm64)
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	7.0.5
	7.0.0
	7.0.0-rc.1.22411.12
	6.0.16
	6.0.14
	6.0.13
	6.0.12
	6.0.11
	6.0.9
	6.0.8

.NET Runtime (x64)
Runtime: /usr/local/share/dotnet/x64/dotnet
Runtime Versions:
	7.0.5
	6.0.16
	6.0.6
	6.0.5
	6.0.4
	5.0.17
	5.0.16
	3.1.29
	3.1.26
	3.1.25
	3.1.24

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

Updater
Version: 11

Xamarin.Android
Version: 13.2.0.0 (Visual Studio Community)
Commit: xamarin-android/d17-5/797e2e1
Android SDK: /Users/huyvu/Library/Android/sdk
	Supported Android versions:
		12.1 (API level 32)
		12.0 (API level 31)
		11.0 (API level 30)
		10.0 (API level 29)
		13.0 (API level 33)

SDK Command-line Tools Version: 7.0
SDK Platform Tools Version: 34.0.1
SDK Build Tools Version: 34.0.0 rc3

Build Information: 
Mono: 6dd9def
Java.Interop: xamarin/java.interop/main@149d70fe
SQLite: xamarin/sqlite/3.40.0@fdc1e34
Xamarin.Android Tools: xamarin/xamarin-android-tools/main@9f02d77

Microsoft Build of OpenJDK
Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk
11.0.16.1
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Eclipse Temurin JDK
Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk
1.8.0.302
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Android SDK Manager
Version: 17.5.0.33
Hash: f0c0c52
Branch: remotes/origin/d17-5~2
Build date: 2023-05-12 16:19:10 UTC

Android Device Manager
Version: 0.0.0.1245
Hash: 7f8a990
Branch: 7f8a990
Build date: 2023-05-12 16:19:10 UTC

Apple Developer Tools
Xcode: 14.3 21812
Build: 14E222b

Xamarin.Mac
Version: 9.3.0.6 Visual Studio Community
Hash: 97731c92c
Branch: xcode14.3
Build date: 2023-04-11 22:38:35-0400

Xamarin.iOS
Version: 16.4.0.6 Visual Studio Community
Hash: 97731c92c
Branch: xcode14.3
Build date: 2023-04-11 22:38:36-0400

Build Information
Release ID: 1705050012
Git revision: 4bfbea94ce18d0c248460d1250770e8e90d3a2ff
Build date: 2023-05-12 16:17:23+00
Build branch: release-17.5
Build lane: release-17.5

Operating System
Mac OS X 13.3.1
Darwin 22.4.0 Darwin Kernel Version 22.4.0
    Mon Mar  6 20:59:28 PST 2023
    root:xnu-8796.101.5~3/RELEASE_ARM64_T6000 arm64


@rolfbjarne
Copy link
Member

This is a duplicate of #18161 (which we'll fix in the next service release).

@rolfbjarne rolfbjarne closed this as not planned Won't fix, can't repro, duplicate, stale May 19, 2023
@filipnavara
Copy link
Member

Workaround is to wrap the delegate when passing it to the inner navigation handler:

-				navigationDelegate.DecidePolicy(webView, navigationAction, decisionHandler);
+				navigationDelegate.DecidePolicy(webView, navigationAction, p => decisionHandler(p));

@ghost ghost locked as resolved and limited conversation to collaborators Jun 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants