Runtime: MulticastDelegate, BeginInvoke throws NotSupportedException

Created on 6 Feb 2016  路  7Comments  路  Source: dotnet/runtime

Invoking the BeginInvoke method of a MulticastDelegate derived delegate compiles fine with .NET Core, but throws a NotSupportedException.
Should this really be the case?
Sample code is here, .NET 4.6 runs ok, but .NET Core fails with the mentioned exception:
https://github.com/ProfessionalCSharp/ProfessionalCSharp6/tree/master/Synchronization/SynchronizationSamples/AsyncDelegate

Thanks,
Christian

area-System.Runtime

Most helpful comment

+1 For compiler safety. How does it make sense to make an API available that is guaranteed to be the wrong thing to use? The ideal experience is for BeginInvoke not to exist on core.

All 7 comments

Async delegates are not in .NET Core for several reasons:

  • Async delegates use deprecated IAsyncResult-based async pattern. This pattern is generally not supported throughout .NET Core base libraries, e.g. System.IO.Stream does not have IAsyncResult-based overloads for Read/Write methods in .NET Core.
  • Async delegates depend on remoting (System.Runtime.Remoting) under the hood. Remoting is not in .NET Core - implementation of async delegates without remoting would be challenging.

Can't this be solved by compilation errors instead of runtime exceptions?

@jaredpar What do you think?

Generally the compiler enables / disables features by looking at the types for hints. Is there anything we can key on here to know to exclude these members?

just refreshing this thread to see if something can be done for compilation errors instead of runtime exceptions

+1 For compiler safety. How does it make sense to make an API available that is guaranteed to be the wrong thing to use? The ideal experience is for BeginInvoke not to exist on core.

Linking back to the official blog post, in case someone comes across the github issue before finding the post. It has some more details and suggestions how to replace Delegate.BeginInvoke invocations.

https://devblogs.microsoft.com/dotnet/migrating-delegate-begininvoke-calls-for-net-core/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aggieben picture aggieben  路  3Comments

matty-hall picture matty-hall  路  3Comments

btecu picture btecu  路  3Comments

bencz picture bencz  路  3Comments

jchannon picture jchannon  路  3Comments