Forum Xamarin.Mac


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Problem with WindowShouldClose

rrradorrrado Member ✭✭

I'm handling WindowShouldClose event in my application like this
public override void ViewWillAppear() { base.ViewWillAppear(); View.Window.WindowShouldClose += Window_WindowShouldClose; }
It used to work until I've moved to new machine with new installation. I guess it is caused by newer Mono or Xamarin, now it throws exception:
Event registration is overwriting existing delegate. Either just use events or your own delegate: TestApp.WindowController AppKit.NSWindow+_NSWindowDelegate
I don't have any class inheriting from NSWindow. How can I solve this? Thank you.

Best Answer


  • rrradorrrado Member ✭✭

    thank you, I've set View.Window.Delegate directly and it works

  • IvanIcinIvanIcin USMember ✭✭✭

    I understand that this has happened by change that you haven't perceived and thus one can't blame you, but will this be the final solution?

    I think that you need to remove this crashing APIs until you find the solution that works out of the box. It can't be acceptable that developers will ship crashing applications for the code that worked.

    Possibly you can set that Window.WeakDelegate = null during the event subscription?

  • IvanIcinIvanIcin USMember ✭✭✭

    View.Window.WeakDelegate = null
    doesn't work

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai
    edited September 2019

    I've filed for us to look into the specifics of this case. If nulling out the WeakDelegate beforehand does not fix it, please reduce it to a simple test case and attach it.

    In general however, assigning to the Delegate property something implementing the protocol instead of using C# Delegates is a preferred pattern, and one you should use whenever possible.

  • IvanIcinIvanIcin USMember ✭✭✭

    Actually I've already submitted it to github but it was closed due to this thread :D . I thought to comment there that it should be opened...

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai
    edited September 2019

    Without a sample (or comment) to show why my advice didn't work, it appeared to be a duplicate at the time.

Sign In or Register to comment.