winforms icon indicating copy to clipboard operation
winforms copied to clipboard

PlatformNotSupported Exception thrown by Delegate.BeginInvoke() method

Open DmitryGaravsky opened this issue 7 years ago • 6 comments

  • .NET Core Version: (Version: 3.0.100-preview-009812)
  • Have you experienced this same bug with .NET Framework?: No

Problem description: The call of the Delegate.BeginInvoke method fires the System.PlatformNotSupportedException:
Operation is not supported on this platform.

It looks like a compatibility bug.

Minimal repro:

  1. Create a new WinForms Core App.
  2. Add the following Code to the Form's code-behind:
protected override void OnShown(EventArgs e) {
    base.OnShown(e);
    Action action = new Action(() => {
        /* do nothing */
    });
    action.BeginInvoke(null, this); // PlatformNotSupportedException thrown here
}

Actual Result: The PlatformNotSupported exception thrown.

Expected behavior: The action should be executed without exception.

P.S. This issue is also cause the #142 issue with PictureBox.LoadAsync method due to following call:

new WaitCallback(this.BeginGetResponseDelegate).BeginInvoke(state, null, null);

DmitryGaravsky avatar Dec 17 '18 13:12 DmitryGaravsky

@OliaG as mentioned in issue #242 and according to https://github.com/dotnet/corefx/issues/5940#issuecomment-182107557 this is intentional and not a bug. It certainly isn't a bug in WinForms.

weltkante avatar Dec 17 '18 20:12 weltkante

We're talking about Delegate.BeginInvoke not about Control.BeginInvoke - the former is part of the framework and not part of WinForms, so this issue is in the wrong place. As linked .NET Core already decided that Delegate.BeginInvoke is intentionally not supported.

weltkante avatar Dec 17 '18 20:12 weltkante

@weltkante Whoops, I misread. Deleted my irrelevant comment.

ArrowCase avatar Dec 17 '18 20:12 ArrowCase

Per @weltkante comment and associated link, I'll close this issue. If you are referring to the Delegate.BeginInvoke is not supported and supposed to throw the exception you found.

merriemcgaw avatar Jan 26 '19 00:01 merriemcgaw

So how are you supposed to work with Nuget packages using this internally?

devedse avatar Mar 01 '19 01:03 devedse

@devedse you may want to ask that over at corefx repo, as said above Control.BeginInvoke from WinForms works just fine, the issue was with Delegate.BeginInvoke which is not part of this repository so you are probably asking the wrong people here.

As far as your question is concerned though, according to the linked discussion, the nuget packes have to be fixed to not use this method if they want to be .NET Core compatible.

weltkante avatar Mar 01 '19 07:03 weltkante