invalidOperationException
xjfjian opened this issue · comments
jianping jia commented
MasterWindowController.cs
throw exception code
Window.DidResize += (sender, e) => {
// Do something as the window is being live resized
};
Window.DidEndLiveResize += (sender, e) => {
// Do something after the user's finished resizing
// the window
};
exception
System.InvalidOperationException: Event registration is overwriting existing delegate. Either just use events or your own delegate: MacWindows.MasterWindowController AppKit.NSWindow+_NSWindowDelegate
at AppKit.NSApplication.EnsureEventAndDelegateAreNotMismatched (System.Object del, System.Type expectedType) [0x0001e] in /Library/Frameworks/Xamarin.Mac.framework/Versions/6.6.0.12/src/Xamarin.Mac/AppKit/NSApplication.cs:112
at AppKit.NSWindow.EnsureNSWindowDelegate () [0x0000e] in /Library/Frameworks/Xamarin.Mac.framework/Versions/6.6.0.12/src/Xamarin.Mac/NSWindow.g.cs:11408
at AppKit.NSWindow.add_DidResize (System.EventHandler value) [0x00001] in /Library/Frameworks/Xamarin.Mac.framework/Versions/6.6.0.12/src/Xamarin.Mac/NSWindow.g.cs:12068
at MacWindows.MasterWindowController.WindowDidLoad () [0x00008] in /Users/anglehuang/Downloads/Xamarin_Mac___MacWindows/MacWindows/MasterWindowController.cs:21
at at (wrapper managed-to-native) AppKit.NSApplication.NSApplicationMain(int,string[])
at AppKit.NSApplication.Main (System.String[] args) [0x00040] in /Library/Frameworks/Xamarin.Mac.framework/Versions/6.6.0.12/src/Xamarin.Mac/AppKit/NSApplication.cs:100
at MacWindows.MainClass.Main (System.String[] args) [0x00007] in /Users/anglehuang/Downloads/Xamarin_Mac___MacWindows/MacWindows/Main.cs:10
Whitney Schmidt commented
@xjfjian Thank you for your feedback!
I was able to reproduce this issue with the default sample code for MacWindows
.
Whitney Schmidt commented
@xjfjian I've put out a PR with a fix for this issue. Please feel free to copy/paste to fix the sample locally on your machine.
There are also a couple other workarounds:
- (Preferred) Stop using C# events and create your own delegate and assign that
- Null out the existing delegate with Window.WeakDelegate = null;
- Disable the safely check with NSApplication.CheckForEventAndDelegateMismatches = false;