Questions tagged [resharper]
ReSharper is a refactoring and productivity extension by JetBrains that extends native functionality of Microsoft Visual Studio versions since 2003.
                                	
	resharper
    
                            
                        
                    
            4,934
            questions
        
        
            1489
            votes
        
        
            18
            answers
        
        
            223k
            views
        
    Virtual member call in a constructor
                I'm getting a warning from ReSharper about a call to a virtual member from my objects constructor. 
Why would this be something not to do?
            
        
       
    
            429
            votes
        
        
            9
            answers
        
        
            177k
            views
        
    Handling warning for possible multiple enumeration of IEnumerable
                In my code I need to use an IEnumerable<> several times, resulting in the ReSharper error of "Possible multiple enumeration of IEnumerable".
Sample code:
public List<object> Foo(...
            
        
       
    
            419
            votes
        
        
            14
            answers
        
        
            84k
            views
        
    Method can be made static, but should it?
                ReSharper likes to point out multiple functions per ASP.NET page that could be made static. Does it help me if I do make them static? Should I make them static and move them to a utility class?
            
        
       
    
            378
            votes
        
        
            90
            answers
        
        
            406k
            views
        
    Tests not running in Test Explorer
                I am currently working on a solution that has currently 32 Unittests. I have been working with the resharper test runner - which works fine. All tests are running, all tests are showing the right test ...
            
        
       
    
            373
            votes
        
        
            13
            answers
        
        
            178k
            views
        
    How can I disable ReSharper in Visual Studio and enable it again?
                I installed ReSharper, and it works in Visual Studio, but how can I disable it?
Whenever I search in the ReSharper menu, I can't find a disable option.
            
        
       
    
            348
            votes
        
        
            40
            answers
        
        
            150k
            views
        
    Visual Studio displaying errors even if projects build
                I have a problem with Visual Studio on a C# solution. It displays totally random errors, but the projects build. Right now, I have 33 files with errors, and I can see red squiggly lines in all of them....
            
        
       
    
            334
            votes
        
        
            25
            answers
        
        
            179k
            views
        
    Invert "if" statement to reduce nesting
                When I ran ReSharper on my code, for example:
    if (some condition)
    {
        Some code...            
    }
ReSharper gave me the above warning (Invert "if" statement to reduce nesting), and ...
            
        
       
    
            323
            votes
        
        
            3
            answers
        
        
            87k
            views
        
    Access to Modified Closure
                string [] files = new string[2];
files[0] = "ThinkFarAhead.Example.Settings.Configuration_Local.xml";
files[1] = "ThinkFarAhead.Example.Settings.Configuration_Global.xml";
//Resharper complains this ...
            
        
       
    
            312
            votes
        
        
            8
            answers
        
        
            113k
            views
        
    LINQ: Not Any vs All Don't
                Often I want to check if a provided value matches one in a list (e.g. when validating):
if (!acceptedValues.Any(v => v == someValue))
{
    // exception logic
}
Recently, I've noticed ReSharper ...
            
        
       
    
            303
            votes
        
        
            5
            answers
        
        
            72k
            views
        
    Why does ReSharper tell me "implicitly captured closure"?
                I have the following code:
public double CalculateDailyProjectPullForceMax(DateTime date, string start = null, string end = null)
{
    Log("Calculating Daily Pull Force Max...");
    var ...
            
        
       
    
            299
            votes
        
        
            3
            answers
        
        
            246k
            views
        
    Where do I mark a lambda expression async?
                I've got this code:
private async void ContextMenuForGroupRightTapped(object sender, RightTappedRoutedEventArgs args)
{
    CheckBox ckbx = null;
    if (sender is CheckBox)
    {
        ckbx = ...
            
        
       
    
            285
            votes
        
        
            4
            answers
        
        
            56k
            views
        
    ReSharper warns: "Static field in generic type"
                public class EnumRouteConstraint<T> : IRouteConstraint
    where T : struct
{
    private static readonly Lazy<HashSet<string>> _enumNames; // <--
    static EnumRouteConstraint()...
            
        
       
    
            262
            votes
        
        
            23
            answers
        
        
            147k
            views
        
    Keyboard shortcuts are not active in Visual Studio with Resharper installed
                I have Visual Studio 2012 + Resharper 7.1.1000.900 + StyleCop 4.7.44  installed.
The problem is that no shortcuts are active since Resharper was installed.
For example: I can still rename via '...
            
        
       
    
            262
            votes
        
        
            17
            answers
        
        
            90k
            views
        
    Resharper Alt Enter not working
                Help, I can't function without Resharper. All of a sudden my Alt+Enter ↵ shortcut (to bring up the action list) has stopped working. Anybody experienced this or know how to fix?
            
        
       
    
            233
            votes
        
        
            23
            answers
        
        
            60k
            views
        
    Why does ReSharper want to use 'var' for everything? [duplicate]
                I've just started using ReSharper with Visual Studio (after the many recommendations on SO). To try it out I opened up a recent ASP.NET MVC project. One of the first and most frequent things I've ...
            
        
       
    
            230
            votes
        
        
            5
            answers
        
        
            242k
            views
        
    What does CultureInfo.InvariantCulture mean?
                I have a string of text like so:
var foo = "FooBar";
I want to declare a second string called bar and make this equal to first and fourth character of my first foo, so I do this like so:
var bar = ...
            
        
       
    
            195
            votes
        
        
            58
            answers
        
        
            147k
            views
        
    Test method is inconclusive: Test wasn't run. Error?
                I have a test class and below I have posted a sample test from the test class
namespace AdminPortal.Tests.Controller_Test.Customer
{
    [TestClass]
    public class BusinessUnitControllerTests
    {
...
            
        
       
    
            195
            votes
        
        
            6
            answers
        
        
            103k
            views
        
    What is the difference between a regular string and a verbatim string?
                I have a trial version of ReSharper and it always suggests that I switch regular strings to verbatim strings. What is the difference?
            
        
       
    
            191
            votes
        
        
            15
            answers
        
        
            49k
            views
        
    How to make ReSharper re-evaluate its assembly reference highlighting
                I am creating a Prism Project Template, and the template works great. But after I create a project with the template some of the files look like this:
Despite appearances, everything is just fine.
...
            
        
       
    
            187
            votes
        
        
            6
            answers
        
        
            69k
            views
        
    Unable to type in Visual Studio
                I am unable to edit any files in a project in Visual Studio 2013.  It only happens in one project.  If I open a different project I am able to type fine, but once I go back into the problem project I ...
            
        
       
    
            185
            votes
        
        
            8
            answers
        
        
            177k
            views
        
    What are some alternatives to ReSharper? [closed]
                I'm considering purchasing a ReSharper license, but are there any possible alternatives to ReSharper and how would you rate these compared to ReSharper?
It doesn't necessarily have to be a free ...
            
        
       
    
            181
            votes
        
        
            13
            answers
        
        
            177k
            views
        
    How do I generate a constructor from class fields using Visual Studio (and/or ReSharper)?
                I've gotten accustomed to many of the Java IDEs (Eclipse, NetBeans, and IntelliJ IDEA) providing you with a command to generate a default constructor for a class based on the fields in the class.
For ...
            
        
       
    
            180
            votes
        
        
            4
            answers
        
        
            165k
            views
        
    Why should I use var instead of a type? [duplicate]
                Possible Duplicate:
  ReSharper and var  
After I have installed ReSharper it demands(by warnings) that I use var whenever possible, for example
UnhandledExceptionEventArgs ue = (...
            
        
       
    
            180
            votes
        
        
            7
            answers
        
        
            70k
            views
        
    String Interpolation vs String.Format
                Is there a noticeable performance difference between using string interpolation:
myString += $"{x:x2}";
vs String.Format()?
myString += String.Format("{0:x2}", x);
I am only ...
            
        
       
    
            169
            votes
        
        
            2
            answers
        
        
            27k
            views
        
    Why is '397' used for ReSharper GetHashCode override?
                Like many of you, I use ReSharper to speed up the development process. When you use it to override the equality members of a class, the code-gen it produces for GetHashCode() looks like:
    public ...
            
        
       
    
            152
            votes
        
        
            2
            answers
        
        
            68k
            views
        
    C# 8 understanding await using syntax [duplicate]
                I have next method:
public async Task<IEnumerable<Quote>> GetQuotesAsync()
{
    using var connection = new SqlConnection(_connectionString);
    var allQuotes = await connection....
            
        
       
    
            147
            votes
        
        
            0
            answers
        
        
            8k
            views
        
    Does inverting the "if" improve performance? [duplicate]
                I've been using ReSharper for a while now and sometimes it suggests that I invert the if. I guess an example would be a better explanation of my situation:
public void myfunction(int exampleParam){
  ...
            
        
       
    
            146
            votes
        
        
            9
            answers
        
        
            23k
            views
        
    ReSharper Abbreviations List: Where can I modify it?
                I am using ReSharper 4.5, and what often happens when I am converting explicit properties into auto-properties, is that I will accidentally chose "Add XX to abbreviations list".
Ie: I want to convert ...
            
        
       
    
            140
            votes
        
        
            2
            answers
        
        
            15k
            views
        
    Disable C# 6.0 Support in ReSharper
                While using ReSharper, it suggested "Enable C# 6.0 support for this project". I foolishly clicked on it, and now as advertised it's giving me suggestions for C# 6.0 - which then give me errors as I am ...
            
        
       
    
            131
            votes
        
        
            10
            answers
        
        
            40k
            views
        
    Disable, but not uninstall Resharper 4.x onwards
                Any ideas on how to disable, but not uninstall Resharper 4.x or above?
            
        
       
    
            130
            votes
        
        
            2
            answers
        
        
            46k
            views
        
    Resharper- Find all unused classes
                I know how to find unused references of a single file by right clicking on the file and selecting the "Find Usages" option. Is there any way I can see or get the list of all the unused classes or ...
            
        
       
    
            127
            votes
        
        
            3
            answers
        
        
            34k
            views
        
    "Delegate subtraction has unpredictable result" in ReSharper/C#?
                When using myDelegate -= eventHandler ReSharper (version 6) issues:
  Delegate subtraction has unpredictable result
The rational behind this is explained by JetBrains here. The explanation makes ...
            
        
       
    
            126
            votes
        
        
            7
            answers
        
        
            25k
            views
        
    ReSharper Curiosity: "Parameter is only used for precondition check(s)."
                Why is ReSharper judging me for this code?
    private Control GetCorrespondingInputControl(SupportedType supportedType, object settingValue)
    {
        this.ValidateCorrespondingValueType(...
            
        
       
    
            124
            votes
        
        
            7
            answers
        
        
            75k
            views
        
    'is' versus try cast with null check
                I noticed that Resharper suggests that I turn this:
if (myObj.myProp is MyType)
{
   ...
}
into this:
var myObjRef = myObj.myProp as MyType;
if (myObjRef != null)
{
   ...
}
Why would it suggest ...
            
        
       
    
            123
            votes
        
        
            7
            answers
        
        
            33k
            views
        
    Visual Studio or Resharper functionality for placement of using directives
                I like to put my using directives inside the current namespace, and not outside as VS and Resharper per default puts them.
Does anyone know of a macro/standard functionality that sorts/removes unused ...
            
        
       
    
            118
            votes
        
        
            1
            answer
        
        
            3k
            views
        
    How do you tell Resharper that a method parameter is a string containing a CSS class?
                [Enable intellisense on HTMLHelper attribute for css classes]
I have this HTMLhelper:
public IHtmlString MyTextBoxFor<TModel, TProperty>(
    this HtmlHelper<TModel> html, 
    Expression&...
            
        
       
    
            116
            votes
        
        
            1
            answer
        
        
            13k
            views
        
    Extract method to already existing interface with ReSharper
                I'm adding a new method to a class that implements an interface, and I like to use the "Extract Interface" refactoring and just add the method to the interface. But it doesn't seem like ReSharper ...
            
        
       
    
            116
            votes
        
        
            3
            answers
        
        
            92k
            views
        
    Moq: Invalid setup on a non-overridable member: x => x.GetByTitle("asdf")
                Not sure how I can fix this, trying to do a unit test on the method "GetByTitle"
Here are my definitions:
public class ArticleDAO :  GenericNHibernateDAO(IArticle, int>, IArticleDAO
{
    public ...
            
        
       
    
            115
            votes
        
        
            5
            answers
        
        
            57k
            views
        
    Uninstall ReSharper 4.5
                I have ReSharper 4.5 in Visual Studio 2008. Now I want to install ReSharper 5, but I can't do it before I uninstall ReSharper 4.5.
How can I uninstall ReSharper 4.5?
            
        
       
    
            110
            votes
        
        
            2
            answers
        
        
            39k
            views
        
    Do I need to maintain ReSharper's dotsettings.user file in Source Control?
                I noticed ReSharper has created a dotsettings.user in my Source folder. 
Do I need to keep this in my Source Control (TFS)? 
If I exclude it, what are the consequences? 
If I get latest on another ...
            
        
       
    
            107
            votes
        
        
            7
            answers
        
        
            27k
            views
        
    ReSharper - force curly braces around single line
                Can I configure ReSharper to fix C# code when curly braces are not used to surround a single-line code block, like this:
if (blnSomeCondition)
   DoSomething();  // complain
if (...
            
        
       
    
            101
            votes
        
        
            1
            answer
        
        
            42k
            views
        
    How can I use ReSharper to list unused methods in a solution? [duplicate]
                In a legacy ASP.NET project I have inherited, there are an abundance of methods defined  which are used absolutely nowhere.  
I'm familiar with the "Find usages" functionality, but would like to be ...
            
        
       
    
            101
            votes
        
        
            1
            answer
        
        
            14k
            views
        
    Access to Modified Closure (2)
                This is an extension of question from Access to Modified Closure. I just want to verify if the following is actually safe enough for production use.
List<string> lists = new List<string>()...
            
        
       
    
            99
            votes
        
        
            2
            answers
        
        
            13k
            views
        
    ReSharper Error: "The output has reached the limit and was truncated. To view the full output use 'Show Stack Trace in a new window' action."
                When running unit tests in ReSharper, if the output is too long, it gives this error:
The output has reached the limit and was truncated.
To view the full output use 'Show Stack Trace in a new window'...
            
        
       
    
            96
            votes
        
        
            8
            answers
        
        
            51k
            views
        
    Advantages of using const instead of variables inside methods
                Whenever I have local variables in a method, ReSharper suggests to convert them to constants:
// instead of this:
var s = "some string";
var flags = BindingFlags.Public | BindingFlags.Instance;
// ...
            
        
       
    
            94
            votes
        
        
            36
            answers
        
        
            12k
            views
        
    What ReSharper 4+ live templates for C# do you use? [closed]
                What ReSharper 4.0 templates for C# do you use?
Let's share these in the following format:
[Title]
Optional description  
Shortcut: shortcut
Available in: [AvailabilitySetting]
// Resharper ...
            
        
       
    
            91
            votes
        
        
            18
            answers
        
        
            53k
            views
        
    Ctrl+R, Ctrl+R command not working
                I'm attempting to use the Ctrl+R, Ctrl+R command within Visual Studio 2008 to rename a variable.  I get an error message at the bottom saying that 
"The key combination (Ctrl+R, Ctrl+R) is bound to ...
            
        
       
    
            89
            votes
        
        
            24
            answers
        
        
            141k
            views
        
    Why can't I reference my class library?
                I have a solution that contains a website and a class library in Visual Studio 2008. 
I then have another web site project outside of the solution that needs to reference the class library. I right ...
            
        
       
    
            88
            votes
        
        
            5
            answers
        
        
            19k
            views
        
    Impure method is called for readonly field
                I'm using Visual Studio 2010 + ReSharper and it shows a warning on the following code:
if (rect.Contains(point))
{
    ...
}
rect is a readonly Rectangle field, and ReSharper shows me this warning:
&...
            
        
       
    
            86
            votes
        
        
            5
            answers
        
        
            58k
            views
        
    Resharper's example code for explaining "Possible multiple enumeration of IEnumerable"
                Sometimes Resharper warns about:
  Possible multiple enumeration of IEnumerable
There's an SO question on how to handle this issue, and the ReSharper site also explains things here. It has some ...