The issue will happen all of the below condition met:
- The intercepted method has return value.
- The intercepted method throws an exception.
- 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.