Local variable is never used

I'm having a problem with ReSharper giving obviously wrong advice. For example, in the following code sample, ReSharper is saying that the

response
,
dates
, and
ex
variables are never used, when they are clearly used on the following lines:
Dim response As New WcfResponseBoolean
Try
    ' ReSharper identifies 'b' as unused, but it is used on the next line.
    b = Builders.CastBuilderFromSession

    If b Is Nothing Then
    response.SetSessionExpired()
        Return response
    End If

    ' ReSharper identifies 'dates' as unused, but it is used on the next line.
    Dim dates As New List(Of DateTime)({ConvertToUSDateTime(inWithTime)})

    CompareDateList(response, inTimeToCompare, New ComparableDatesList() 
        With {.Dates = dates, .CheckCompareType = compareType}, False)

' ReSharper identifies 'ex' as unused, but it is used on the next line.
Catch ex As Exception
    MailHandler.SendExceptionEmailToBTDebug(ex, "CompareDates")
    response.SetUnhandledException()
End Try

I've followed the advice from this link to try clearing ReSharper's caches by going to ReSharper --> Options --> Environment --> General and clicking the "Clear Caches" button. But when I click that button, I get no feedback from ReSharper that anything happened. The screen just sits there; no popup message, no UI feedback of any kind. And when I click the Save button to close the form, the problem persists.

I've also tried cleaning and rebuilding the project, and closing and opening Visual Studio. Neither of these have had any effect. The only two things I can think to do from here are:

  1. Delete ReSharper's cache files manually. But I don't know where they are located, and I'm not sure that is safe to do.
  2. Uninstall and reinstall ReSharper. But that seems drastic. I'd prefer not to do this unless it is the only option left.



TL;DR:
Is there a different way I can clear ReSharper's cache? Failing that, is there a different way to get the static analyzer working again?

I'm running ReSharper 8.1.23.546 in Visual Studio 2012 (version 11.0.61030.0).


(I originally posted this at StackOverflow -- this question -- but it is probably more appropriate here.)

2 comments
Comment actions Permalink

Update:

I found the location of the cache files, at

%LOCALAPPDATA%\JetBrains\ReSharper\v8.1\SolutionCaches
. I deleted these files manually, and that didn't fix it.

I also tried uninstalling and reinstalling ReSharper, and unfortunately that didn't fix it either.

I am out of ideas here. I hope someone has something else for me to try.
0
Comment actions Permalink

I think it is unwise to spend too much time on things that are not really issues that can break your program.  An unused variable or even many of them will not cause your program to crash, thus cleaning them is a purely matter of style.

If you do not want to be warned of a particular unused variable, then use the Options on the action menu and set to Disable once with comment.  This will alert Resharper to not warn you about this particular variable while all others will still be reported.  What you are doing is simply correcting an error in Resharper not recognizing a certain thing, and the important thing is you can forget about it and get back to coding more important things.

Resharper might not be perfect, but it is still really good and the advice it provides is of immense help.  As in all things you are the one to decide whether to ignore advice, and of course, my advice falls into that category too.

-8

Please sign in to leave a comment.