Weird "cannot resolve symbol" error ... in a string?
I have code that looks like this:
var operation = request.OperationName;
if (string.IsNullOrEmpty(operation))
{
throw new ArgumentNullException("request.OperationName");
}
For some reason, the string "request.OperationName" is underlined, and the
error when I hover over it is "Cannot resolve symbol
'request.OperationName'". The quick-fix offers to "Fix argument text", and
if I do, it just removes the "OperationName".
But this is just string data. It's data in the exception to let us know
what is wrong. Why is ReSharper even looking at it? Is this some ASP.NET
stuff leaking through to regular C# code?
This is on 5.1 release build.
Please sign in to leave a comment.
Hello Paul,
According to .NET Framework documentation the ArgumentNullException(string
argumentName) constructor expects the name of some method argument. ReSharper
provides a special analysis which checks that ArgumentNullException constructor
parameter corresponds to some method argument (and issues a warning if it
doesn't). Thank you!
Andrey Serebryansky
Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
Do you think it would be possible to provide a more helpful message for this? It is extremely confusing and unlike other errors where I can "inspect the options" to see what the R# behavior is, there seems to be no option for this.
Hello Tyler,
Surely the 'Cannot resolve symbol' message is misleading and we will try
to come up with a better message in one of the future releases. You can watch
the status of the following issue: http://youtrack.jetbrains.net/issue/RSRP-188905.
Thank you!
Andrey Serebryansky
Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
Well, here's the thing, in my example (reposted below), I the parameter is
the method argument. There argument is a class with multiple fields, so the
code validates the fields on the incoming parameter individually and wants
to specify which one was bad.
So "request" is the method argument. The code is validating
"request.OperationName".
Thus, IMHO, this is a valid case, and shouldn't be marked as an error. We
want the exception to be specific to what is wrong (subsequent code might
test, say, request.OperationDescription, just for the sake of argument).
Am I missing something here?
"Andrew Serebryansky" <andrew.serebryansky@jetbrains.com> wrote in message
news:c8a898dd961f8cd01ecd00d2a38@news.intellij.net...
>
>
>
>> I have code that looks like this:
>>
>> var operation = request.OperationName;
>> if (string.IsNullOrEmpty(operation))
>> {
>> throw new
>> ArgumentNullException("request.OperationName");
>> }
>> For some reason, the string "request.OperationName" is underlined, and
>> the error when I hover over it is "Cannot resolve symbol
>> 'request.OperationName'". The quick-fix offers to "Fix argument
>> text", and if I do, it just removes the "OperationName".
>>
>> But this is just string data. It's data in the exception to let us
>> know what is wrong. Why is ReSharper even looking at it? Is this
>> some ASP.NET stuff leaking through to regular C# code?
>>
>> This is on 5.1 release build.
>>
>