xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.44k stars 509 forks source link

InvalidOperationException can occur when using C# events for delegate if Apple sets a default delegate #7569

Open whitneyschmidt opened 4 years ago

whitneyschmidt commented 4 years ago

We have seen a number of “regressions”, for example from https://github.com/xamarin/mac-samples/issues/123 in MacWindows sample:

public override void WindowDidLoad ()
{
    base.WindowDidLoad ();

        // adding Window.WeakDelegate = null here "resolves" the issue
    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
    };
}

The Window.DidResize event throws since Apple started assigning a default delegate they didn’t used to.

You have three options:

whitneyschmidt commented 4 years ago

FYI @chamons

Gidea-code commented 4 years ago

中国人表示看不懂

呵呵

chamons commented 4 years ago

Welcome @seattle-a @Gidea-code @dbudaiya - I'm unsure if you are discussing the issue at hand or something unrelated, automated translation is sometimes inaccurate.

As noted here: https://github.com/xamarin/xamarin-macios/wiki/How-to-Contribute#discussion-etiquette

Whenever possible, we ask that conversations on issues be done in English. We have a global community, and that lets the most people participate.

Thanks!

dushenyan commented 2 years ago

Sorry to leave the language garbage in the warehouse early in the learning stage

Message deleted!