-
Notifications
You must be signed in to change notification settings - Fork 515
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
Apple change causing "Event registration is overwriting existing delegate" exception to fire when using C# events of NSWindowDelegate #6898
Comments
We currently believe this is macOS only, but could affect iOS in a similar way. We should research into what change from Apple is causing this, if we should special case it in our warning. The general idea, warn when C# events cause the underlying delegate to be overwritten, is still solid however. |
Just to explain implications on my example. I had one subscription to WillClose in one one not so important window. As such it is almost never tested without particular reason and after it was compiled with the latest software it started to crash, users reported that. This can happen to any app produced with Xamarin, actually it is certain that there will be more cases like this one. That's why I think that this needs to be fixed in some way (and I was a bit angry when the bug for this case I have submitted was closed: #6884 ), though I've stayed away from any angry comments there. |
I made some experiments on the issue and there are my 2 cents. We have two versions of the same app:
We run the apps on the same Mojave machine. The code that was used to build the both apps is absolutely the same. The only difference is our build environment, I'm pretty sure we have installed Mono updates which go with Visual Studio for Mac updates. Our current Mono version is 6.0.0.334. Hope this helps. |
Were they built with the same Xcode? Often Apple will silently opt-in new behavior when you build with a new enough Xcode. My assertion, as noted above, is that Apple changed this behavior recently. |
Thank you for the quick reply.
I'm not sure actually. I think we updated Xcode as well. I'll try to figure it out and reply back if I find some confirmation. |
Update: we did not update Xcode. Just to double-check, I've made the following tests today. I've build the same app using two build configurations:
The first app works fine, the second app crashes with "Event registration is overwriting existing delegate". |
Original bug: https://forums.xamarin.com/discussion/comment/387768/#Comment_387768
public override void ViewWillAppear() { base.ViewWillAppear(); View.Window.WindowShouldClose += Window_WindowShouldClose; }
Exception:
Event registration is overwriting existing delegate. Either just use events or your own delegate: TestApp.WindowController AppKit.NSWindow+_NSWindowDelegate
It appears that Cocoa in some update is assigning a default delegate on Windows, and the exception is warning/complaining that we're overwriting it blindly. From what I can tell, this is a behavior change from Apple.
You can either:
Stop using the events and assign a View.Window.Delegate directly
OR
Set
View.Window.WeakDelegate = null
before assigning your first eventOR
If you want to completely disable the safety set
NSApplication.CheckForEventAndDelegateMismatches
tofalse
The text was updated successfully, but these errors were encountered: