Skip to content

Bugfix/cannot await dynamic for non public type#268

Merged
liuhaoyang merged 8 commits intomasterfrom
bugfix/cannot-await-dynamic-for-non-public-type
Aug 25, 2021
Merged

Bugfix/cannot await dynamic for non public type#268
liuhaoyang merged 8 commits intomasterfrom
bugfix/cannot-await-dynamic-for-non-public-type

Conversation

@huoshan12345
Copy link
Copy Markdown
Collaborator

@huoshan12345 huoshan12345 commented Jul 21, 2021

if we use await (dynamic)value to await a Task<T> or ValueTask<T> when T is non-public, we will get a RuntimeBinderException that says one of following messages:

  • Cannot implicitly convert type 'void' to 'object'
  • 'System.ValueType' does not contain a definition for 'GetAwaiter'.

This PR has fixed this issue.

@huoshan12345 huoshan12345 linked an issue Jul 21, 2021 that may be closed by this pull request
@huoshan12345 huoshan12345 requested a review from liuhaoyang July 21, 2021 09:49
@huoshan12345 huoshan12345 self-assigned this Jul 30, 2021
@huoshan12345
Copy link
Copy Markdown
Collaborator Author

huoshan12345 commented Aug 7, 2021

The benchmark for several ways of getting value of Task<T>.Result without knowing the compile type of the task

Method Mean Error StdDev StdErr Min Q1 Median Q3 Max Op/s Ratio RatioSD Gen0 Gen1 Gen2 Allocated
GetTaskResult_ReflectionWithCache 262.4ns 0.39ns 0.34ns 0.09ns 262.0ns 262.2ns 262.3ns 262.5ns 263.3ns 3,810,728.6 2.33 0.00 0.0086 - - 144B
GetTaskResult_ExpressionWithCache 124.6ns 1.81ns 1.69ns 0.44ns 122.2ns 123.0ns 124.8ns 125.6ns 127.6ns 8,028,241.9 1.10 0.02 0.0086 - - 144B
GetTaskResult_AwaitDynamic 112.7ns 0.24ns 0.20ns 0.06ns 112.5ns 112.5ns 112.6ns 112.8ns 113.2ns 8,873,388.6 1.00 0.00 0.0172 - - 288B
GetTaskResult_DynamicDelegateWithCache 125.9ns 0.73ns 0.69ns 0.18ns 124.6ns 125.5ns 125.6ns 126.6ns 126.8ns 7,945,539.9 1.12 0.01 0.0086 - - 144B
GetTaskResult_DynamicMethodWithCache 125.1ns 1.18ns 1.11ns 0.29ns 123.8ns 124.2ns 124.8ns 126.1ns 126.9ns 7,995,479.2 1.11 0.01 0.0086 - - 144B

NOTE:
GetTaskResult_DynamicDelegateWithCache uses Delegate.CreateDelegate
GetTaskResult_DynamicMethodWithCache uses DynamicMethod and ILGenerator

@liuhaoyang liuhaoyang merged commit cef611f into master Aug 25, 2021
@liuhaoyang liuhaoyang deleted the bugfix/cannot-await-dynamic-for-non-public-type branch October 9, 2023 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot implicitly convert type 'void' to 'object'

2 participants