-
Notifications
You must be signed in to change notification settings - Fork 471
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
Replace NullReferenceException thrown when interceptors swallow exceptions and cause a null value type to be returned #364
Conversation
ae3aedc
to
5991c32
Compare
I haven't done a detailed code review but run a few quick tests against this PR. It appears to be doing what it should. 👍 I found one minor issue regarding using Castle.DynamicProxy;
using System;
class Program
{
static void Main()
{
var generator = new ProxyGenerator();
var proxy = generator.CreateInterfaceProxyWithoutTarget<IFoo>(new Interceptor());
int x = 0;
proxy.GetValue(ref x);
}
}
class Interceptor : IInterceptor
{
public void Intercept(IInvocation invocation)
{
invocation.Arguments[0] = null;
}
}
public interface IFoo
{
void GetValue(ref int x);
} Then you get an error mentioning
In general, I am not sure if the additional check is needed at all for |
I was wondering that too, it is probably unlikely someone would set an argument to null and wonder why it doesn't work. So remove the parameter check, and keep the return value check? |
@stakx do you think the exception message is clear enough, or could be worded better/differently? |
The argument check is probably a good idea for |
If you run the code you provided above with master you'll get a I can fix the exception to mention "ref" rather than "out", that was my mistake. |
Generally, as a hint at the possible error source, it's definitely clear enough. The following points are just minor fine-tuning suggestions:
|
I need to take this back, I didn't realise that So yes, perhaps the check could be removed completely for all by-ref parameters (even |
5991c32
to
b5cd585
Compare
Yep, your suggestions for the exception message make sense, done. And removed the parameter check. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Seems a bit silly to me that I dare "approve" the project owner's own PR, but well... it's GitHub's wording. :)
Looks good to me! 👍
…tions and cause a null value type to be returned
b5cd585
to
d75e5b3
Compare
See #85.