Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DynamicProxy Throw NullReferenceException When Intercepted Method Throw Eaten Exception #85

@Charles-521

Description

@Charles-521

The issue will happen all of the below condition met:

  1. The intercepted method has return value.
  2. The intercepted method throws an exception.
  3. The above exception is handled in _public void Intercept(IInvocation invocation)_ and it is NOT re-thrown.

We put our logging logic when the exception happens and since we do not intend to crash the application. Therefore such exception does not re-thrown.

Currently I can workaround this by putting below code in _finally block_:

if (!invocation.Method.ReturnType.IsClass
    && !invocation.Method.ReturnType.IsInterface
    && invocation.Method.ReturnType.Name != "Void"
    && invocation.Method.ReturnParameter != null
    && invocation.ReturnValue == null)
        invocation.ReturnValue = Activator.CreateInstance(invocation.Method.ReturnType);

However, it might be better to handle this in the framework itself.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions