Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AsyncInterceptor cannot handle exeptions #52

Open
ladenedge opened this issue Nov 27, 2019 · 2 comments
Open

AsyncInterceptor cannot handle exeptions #52

ladenedge opened this issue Nov 27, 2019 · 2 comments

Comments

@ladenedge
Copy link
Contributor

AsyncInterceptor is awesome, but it cannot handle faulted tasks.

On first glance it looks like one could override AfterInvoke(IInvocation invocation, Task task) and check the IsFaulted property of the task, but the last ContinueWith() contains this code:

invocationClone.ReturnValue = t.Result;
this.AfterInvoke(invocationClone);
this.AfterInvoke(invocationClone, t);
return (TResult)invocationClone.ReturnValue;

Thus, AfterInvoke() is only called if task.Result does not throw—which it will if the task is faulted!

What I believe is needed is a check of t.IsFaulted before accessing t.Result and then calling the virtual methods appropriately.

ladenedge pushed a commit to ladenedge/Ninject.Extensions.Interception that referenced this issue Nov 27, 2019
@ladenedge
Copy link
Contributor Author

Please see #53 for the PR that resolves this issue. Thank you!

ladenedge pushed a commit to ladenedge/Ninject.Extensions.Interception that referenced this issue Dec 5, 2019
…or multiple interceptors. Also full support for HandleExceptions and CompleteInvoke in both async and sync scenarios.
scott-xu pushed a commit that referenced this issue Feb 12, 2021
* #52 - Added check for faulted task in AsyncInterceptor and associated tests.

* Reverted a C# 8 feature.

* #52 - The AsyncInterceptor now "pipelines" results, allowing for multiple interceptors.  Also full support for HandleExceptions and CompleteInvoke in both async and sync scenarios.

Co-authored-by: Jay Miller <jay.miller@verint.com>
@iandawson
Copy link

Any chance of releasing the nuget package which includes this fix?

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

No branches or pull requests

2 participants