Detecting and Solving Memory Problems in .NET E-Book

In the past we’ve published a series of blog posts about detecting and solving memory issues in .NET applications, most, if not all, authored by Alexey Totin, Technical Writer on the .NET Team.

We’ve now aggregated all these posts, touched them up, and made them available as a single E-Book that you can download for free.

Book Cover

It’s the second book of the JetBrains Technical Series, first one being What to look for in a Code Review. And there are more books in the works!

Enjoy.

Posted in How-To's | 4 Comments

ReSharper Ultimate 2016.1 (formerly 10.1) EAP 6

Hello everyone. This week we have published a new EAP build of ReSharper Ultimate 2016.1 (formerly referred to as ReSharper Ultimate 10.1), bringing new fixes and improvements.

(If you’re wondering why a sudden change of versioning, please see JetBrains Toolbox — Release and Versioning Changes.)

Below is what we have added in this latest build.

ReSharper

Out-of-the-box xUnit.net support

The xUnit.net test framework has seen a large rise in popularity recently, including being the framework of choice for Microsoft’s cross platform, open source .NET Core project, and is the officially supported way of running tests for DNX projects.

While ReSharper has had support for xUnit.net for many years, it has always required installing a separate extension. Starting with EAP 6, ReSharper now provides support for xUnit.net directly in the product. This means ReSharper will discover your tests, and allow you to run and debug them, right from the editor, without requiring any extra extensions.

Furthermore, ReSharper Ultimate users will also be able to profile tests, get code coverage and use xUnit.net in Continuous Testing sessions.

One thing to note is that this build does not yet support running tests for DNX projects, this will hopefully be included in a future build.

New code style features

There are two new features to further extend the level of detail of your code style. As usual with code style, the new features are configurable and can be applied as part of code cleanup.

Using named/positional arguments

Consider the following method call:

AddCheckbox(true, true, "AutoFill", null);

When you read this code, you have to stop and examine the method signature to understand what happens here. With named arguments, the call becomes much clearer:

AddCheckbox(enabled: true, value: true, label: "AutoFill", tooltip: null);

Now, if you prefer to have named arguments for specific types, you can do so with a little help from ReSharper. In the Code Editing | C# | Code Style page of ReSharper options, define for which types of parameters you prefer to use named arguments, and the corresponding suggestions will be added to the list of quick-fixes:

Code style for named/positional arguments

In addition, even if you do not have any style preferences for arguments, you can always press Alt+Enter on any named or positional argument and choose to add or remove the argument name.

Braces for single-line statements

C# specification allows you to safely omit braces around single nested statements in some parent statements, e.g. if-else, foreach, etc. However, code style guidelines may differ in this regard: some consider the braces here as a requirement, some consider them redundant.

Whatever style you prefer, ReSharper now helps you have consistent use of braces throughout your code base. Preferences for each kind of code block can be configured separately in a code style options page, and ReSharper makes sure to respect these preferences:

Braces style for single-line statements

Here is the full list of fixes for ReSharper in this EAP build.

dotCover

This build brings some bug fixes and a few UI improvements to the Continuous Testing Session window. Quick search results are now highlighted in the coverage tree, and a button is added to explore the stack trace of the selected test in Stack Trace Explorer:

Improvements in Continuous Testing window

dotMemory Unit 2.2

There is another small improvement that have to do with dotMemory Unit. While only constant values can be used when initializing attribute properties, there was a problem of defining user-specific directories for DotMemoryUnitAttribute.Directory property when saving workspaces. Now there are three new constants that evaluate to %USERPROFILE%, %APPDATA%, and %LOCALAPPDATA%. You can either use the constants from the SpecialDirectory class, e.g:

[DotMemoryUnit(Directory = SpecialDirectory.User + "MySubDirectory")]

or simply write one of these constants in angle bracketes (<User> | <CommonApplicationData> | <LocalApplicationData&gt), e.g:

[DotMemoryUnit(Directory = @"<User>/MySubDirectory")]

The mandatory call to action

If you haven’t done it already, please download the latest ReSharper Ultimate 2016.1 EAP build.

To provide any feedback, please use the comments here or report problems to issue trackers of affected products: ReSharper, ReSharper C++, dotTrace, dotCover, dotMemory, dotPeek.

Posted in News and Events | Tagged , , , , , | 13 Comments

ReSharper Ultimate 10.1 EAP 5

A new EAP build of ReSharper Ultimate 10.1 is now available for download. We continue to stabilize and improve the upcoming 10.1 release, and here is what we have added this week:

ReSharper

Dedicated action for reformatting code

In early versions of ReSharper, ‘Reformat Code’ was the only code style feature and it proudly possessed its own action. In version 4.0, back in 2008, a number of new code style features were added, ‘Reformat Code’ was replaced by ‘Code Cleanup’ and became a part of it. ‘Code Cleanup’ has been further evolving and now includes more than a dozen features in most of supported languages, and so we felt like ‘Reformat Code’ got lost among all these features.

Therefore, we decided to restore the dedicated action for reformatting code, which you can now invoke from the main menu (ReSharper | Edit | Reformat Code) or with a shortcut (Ctrl+Alt+Enter in Visual Studio scheme or Ctrl+Alt+L in ReSharper 2.x/IntelliJ IDEA scheme).

As before, the scope of reformatting code depends on the context:

  • If there is a selection in the editor, the selection is refomatted.
  • If the cursor is in the editor without selection, the whole document is refomatted.
  • If the focus is in the Solution Explorer, all documents in the selected solution nodes are reformatted.

Full support for TypeScript 1.8

If you are experimenting with TypeScript 1.8, you can be sure that ReSharper fully understands every single one of the latest TypeScript features. This includes type parameter constraints, stateless JSX components, augmenting global/module scope, string literal types, and this-based type guards.

File Structure for JSON documents

Initial support for JSON files and schemas, which was introduced earlier in ReSharper Ultimate 10.1 EAP, is now complemented with the File Structure view:
File Structure for JSON documents

Here is the full list of fixes for ReSharper in this EAP build.

dotCover

dotCover 10.1 now speeds up test execution in Continuous Testing for MSTest and xUnit tests by pre-loading test runners. Previously, this was only available for NUnit tests.

Another improvement applies to the relationship between dotCover console runner and TeamCity. TeamCity is now tuned to understand the output of the console runner and can highlight its errors and warnings in the build log:

dotCover errors in TeamCity log

dotMemory Unit 2.2

Along with this ReSharper Ultimate build, we have published an EAP build of dotMemory Unit, our .NET memory testing framework. This includes the following improvements:

  • Object selection queries now support open generic types, which is useful if you want to get all substitutions of your generic type.
  • You can select objects by wildcards using the Like and NotLike queries on types, interfaces, and namespaces.
  • Improved performance of key queries: Type.Is, Interface.Is and Namespace.Like.
  • Tests that execute queries from child processes are now handled correctly.

dotMemory Unit 2.2 new object selection queries

We welcome you to participate in this early access program and download the latest ReSharper Ultimate 10.1 EAP build.

If you have any feedback to share, please do so here in the comments or use issue trackers of affected products: ReSharper, ReSharper C++, dotTrace, dotCover, dotMemory, dotPeek.

Posted in How-To's | Tagged , , , , | 17 Comments

ReSharper Ultimate 10.1 EAP 4

Hello everyone. We have published another EAP build of ReSharper Ultimate 10.1 this week.

This time it’s almost all about mainline ReSharper. As usual, there’s a number of issues that we fixed in this build: most of them are bug fixes, but there are some new features too.

Convert XML string to a LINQ to XML object

This new context action, which is available wherever you have valid XML inside a string literal, lets you convert this string to a LINQ to XML object (using XElement, XAttribute etc.):

Converting XML string to a LINQ to XML object

Convert JSON string to a Newtonsoft JSON.NET object

Similarly to XML, you can now use a context action that converts a JSON string to a Newtonsoft JSON.NET object:

Converting JSON string into Newtonsoft JSON.NET object

Note that this action is only available if your project references Newtonsoft.Json assembly, which is distributed under MIT License and can be installed from the NuGet Gallery.

Combined with ‘Smart Paste’, which was introduced in the first EAP build of ReSharper 10.1, these two actions complete the workflow of transferring existing XML or JSON into C# code.

JSDoc improvements

The support of JSDoc, which is available starting from ReSharper 9.1, is further improved in this EAP build. ReSharper can now parse generics, HTML markup, and parameters with properties in your JSDoc comments. Everything that ReSharper infers from JSDoc becomes immediately available in code completion suggestions, parameter information tooltip, etc.

JsDoc support improvements in ReSharper 10.1 EAP

You may also notice that in this build there is no ‘Tip of the Day’ anymore. A modal dialog was a rather outdated way of displaying context help and according to our statistics, hardly anyone used this feature. We would like to develop a more usable way of displaying contextual help in future, and we welcome any ideas on how this should look like.

If you are eager to try the changes described in this post, please go on and download ReSharper Ultimate 10.1 EAP.

Should you have any issues with the EAP, please report them to issue trackers of affected products: ReSharper, ReSharper C++, dotTrace, dotCover, dotMemory, dotPeek.

Posted in News and Events | Tagged , , | 14 Comments

ReSharper Ultimate 10.1 EAP 3

Initial builds of ReSharper Ultimate 10.1 EAP introduced lots of improvements and fixes. In contrast, build 3 that was published a few days ago introduces a relatively small set changes and fixes, limited to ReSharper and ReSharper C++.

Please download and try the latest EAP build and let us know how it works for you. Meanwhile here’s a quick summary of what’s new in this build.

ReSharper

Optimize NuGet references

Optimize References learns to handle NuGet references that are now displayed in the same tool window as all the regular references that a project contains. ReSharper also adds a new grouping to show possibly unused references that have dependencies in the project, and thus cannot be considered redundant. ReSharper tells you exactly what particular dependencies from a package are actually used in your project:

Analyze references including NuGet packages

In addition, Remove Unused References now supports NuGet references as well:
remove_unused_references_nuget

ReSharper 10.1 EAP significally improves performance on updating NuGet packages and analyzing project references. It also fixes a set of issues that used to break compilation by erroneously removing references that were in fact in use (which, for instance, used to happen when using the dynamic type).

Other changes

ReSharper 10.1 EAP comes with improved highlighting ranges for errors involving complex types. Previous versions of ReSharper would highlight the entire statement containing an error, which would hinder locating where the error was coming from, especially with complex generic types. From now on, ReSharper highlights only the part of type that is erroneous (however, watch out for Visual Studio 2015’s own error highlighting) and offers more ways to fix mismatching types.
Cleaner highlighting and new quick-fixes when types mismatch

Another set of fixes enhances TypeScript support. ReSharper now correctly handles TypeScript modules installed via npm, which is crucial in AngularJS development. There is also a fix that makes ReSharper properly understand all TypeScript types in DNX/.NET CLI projects.

For the full list of fixes in ReSharper 10.1 EAP3, please refer to our tracker.

ReSharper C++

ReSharper C++ 10.1 EAP3 comes with a set of fixes of its own.

Give it a try

Please download ReSharper Ultimate 10.1 EAP if you like the improvements described above.

If you are experiencing any issues with the EAP, please report them to issue trackers of affected products: ReSharper, ReSharper C++, dotTrace, dotCover, dotMemory, dotPeek.

Posted in News and Events | Tagged , , , , | 6 Comments

Performance profiling in Continuous Integration: an updated dotTrace plugin to TeamCity

A while ago, we introduced the dotTrace plugin to TeamCity. It helps you prevent application performance regression by profiling integration tests on a TeamCity server.

Now we’re releasing the next version of this plugin that brings some significant improvements. Before we move on to the details, let’s recall how the plugin is used for tracking performance in CI builds:

  1. Write an integration test that runs some performance-critical functionality in your application.
  2. In the plugin, set a performance threshold for this test, which is the execution time value in ms or value taken from previous successful builds. Now, if the test exceeds its threshold, the plugin will fail the build and save the collected performance snapshot to build artifacts.
  3. Open the snapshot in dotTrace and find the exact cause of the performance issue.

This simplified workflow description is missing one obvious yet very important step: plugin configuration. The initial plugin required a number of preparatory steps on the build agent side: installing the console unit test runner and creating a rather complex XML configuration file (containing various profiling options, like profiling target, type, and so on). The new release addresses this issue: you no longer need to install the runner or create the configuration file. The trick is that the plugin is now made a part of unit testing build steps. Thus, after installing the plugin, all these build steps (Visual Studio Tests, NUnit, MSpec, and others) get the additional option Run build step under dotTrace profiler.

Plugin integration

Moving profiling under unit testing build steps is also beneficial in one more way. From now on, when the plugin is enabled, you can not only check performance of tests but also track test results as usual (it’s still a “normal” unit testing build step).

Below, we’ll provide the detailed plugin usage example that you can use as a step-by-step guidance for the new dotTrace Plugin for TeamCity.

1. Install the plugin and dotTrace Console Profiler

IMPORTANT! If you use the previous plugin version, uninstall it before proceeding to this step.

  1. On your TeamCity server, download and copy dotTrace.zip to the plugins directory located in your TeamCity data directory. Use guest / guest credentials for download.
  2. Restart the TeamCity Server service.
  3. As the dotTrace console profiling tool is required for the plugin, download dotTrace Command Line Tools and unzip to any directory on a TeamCity build agent.

2. Write an integration test

Suppose we have an application with a killer feature called Foo. For example, we have a Foo class with the Foo() method which, in turn, uses a Goo class. It creates a Goo instance and runs its Goo() method, which also runs some methods. We assume the execution time of the Foo feature is crucial for user experience. So we add a performance NUnit* test that runs the feature:

* The plugin supports all TeamCity .NET unit test runners, but we will use NUnit in our example.

3. Create a build configuration

The next step is to create a build configuration dedicated to performance testing in TeamCity.

IMPORTANT! To help ensure consistency of profiling results, you should assign the build configuration that uses the plugin to a specific build agent (a hardware agent is strongly recommended). For further instructions please refer to TeamCity documentation.

Suppose we already have a project called My Project. Let’s add to that project a configuration consisting of two steps: building the application and running performance tests. To save time, let’s proceed right to configuring the second build step.

  1. In build configuration settings, go to Build Steps and click Add build step.
    Build configuration
  2. In Runner type, select NUnit. (If you use a different testing framework, you would select the appropriate runner type, e.g. MSTest or Visual Studio Tests.)
  3. Set options for NUnit. The main one here is Run tests from — the relative path to the DLL with tests.
  4. Select Run build step under dotTrace profiler.
  5. Set the following plugin options and then click Save:
    • Path to dotTrace ConsoleProfiler.exe: the path to the directory that you have unzipped dotTrace Command Line Tools into. In our example, it’s C:\Console Profiler
    • Measure type: the type of profiling you want to use. We strongly recommend that you use only the Sampling type as it gives the most realistic time values. Note that the plugin does not support Timeline profiling.
    • Performance snapshot artifacts path: set the path relative to the artifacts folder for storing the collected performance snapshot. Keep in mind that, depending on application complexity, the snapshot may take up hundreds of MB of disk space. We recommend updating your artifact cleanup policy so that after some time TeamCity would delete the snapshot folder from artifacts.
    • Threshold values : specify the list of methods whose performance you want to check. The pattern is Namespace.Class.Method TotalTime OwnTime, where
      • TotalTime is the method’s execution time, including its own time and the time of the method’s call subtree, in milliseconds;
      • OwnTime is the method’s own execution time, in milliseconds.

    (Setting a value to zero will make the plugin ignore the threshold.)

    If we want to check the method’s time against the corresponding time in previous successful builds, we have three options: a) we can take values for comparison from the first successful build, b) take them from the last successful build, or c) compare against the average value calculated for all successful builds. If so, instead of the absolute threshold value in milliseconds, we should use one of the following prefixes:
    a) F – take value from the first successful build,
    b) L – take value from the last successful build, or
    c) A – take average value based on all prior successful builds
    Then, set the tolerance to indicate by how much the time value may be exceeded, as a percentage.

dotTrace build step configuration

In our example, we want to track the total execution time of the Foo feature, so we add a threshold for the total time of the TestFooFeature() test. F15 means that the value for comparison (with up to 15% tolerance) must be taken from the first successful build. E.g., if during the first successful build dotTrace measures 1000 ms total time for the method, the method’s threshold for all following builds will equal 1150 ms (1000 + 1000*0.15).

In our example, we also want to check the total time of the Goo() method as it strongly impacts the performance of the Foo feature. Checking the method’s execution time during the build simplifies our job: in case of performance issues with Foo, we will know right away if Goo() is the one to blame. As a threshold for the method, we also use the value from the first successful build, plus 15% tolerance.

4. Set a failure condition

If we want the build step to fail when a test exceeds its performance threshold, we should set a failure condition.

  1. In Build Configuration Settings, go to Failure Conditions.
  2. In Fail build if, select an error message is logged by build runner.

Build step failure condition

5. Run the build

Now it’s time to run the build! As we decided to use values from the first successful build for the thresholds, the first build won’t fail in any case — it is used only to set the baselines for the TestFooFeature() and Goo() methods. The time values from this build will become the “golden standard” for all subsequent builds.

  1. Run the build.
    Build step first runAs TeamCity had no data on the methods’ execution times before the first build, the build passes successfully (the expected values equal 0).
  2. Suppose now that someone has edited the Goo() method and made it slower. We’ll emulate this using Thread.Sleep(200) and re-run the build. Now, the test still passes, but the build fails due to an error:
    Build step second run
    If we now click on the build, we’ll see the following build results:
    Methods that exceeded performance thresholds
    As we instructed the plugin to save a performance snapshot, it has stored the archive with the snapshot in the artifacts Snapshots folder:
    Performance snapshot in build artifacts
    Note that the snapshot consists of a number of files. Now, we can analyze the snapshot and find the exact cause of the performance flaw:
    Snapshot opened in dotTrace
  3. As all values are reported as TeamCity statistic values, so you can build trend graphs for the measured time values if you like. To do this, open the Parameters tab of any build and switch to Reported statistic values:
    Reported statistic valuesClick View trend for a particular parameter to see its diagram of changes:
    Statistic value trend

Summary

As this post has illustrated, the updated dotTrace plugin for TeamCity no longer requires complex configuration, which makes it easier to use. To check it out on your own, please download the plugin (remember to use guest / guest credentials to download). As always, we’d be happy to hear any feedback from you. Feel free to ask any questions in the comments to this post.

Profile with pleasure!

Posted in dotTrace Tips&Tricks, How-To's | Tagged , , , | 5 Comments

ReSharper Ultimate 10.1 EAP 2

The first EAP build of ReSharper Ultimate 10.1 introduced a massive list of new features and improvements, which spanned two blog posts. And here we are today with another EAP build, which you can give a try right away.

ReSharper

The most notable changes in ReSharper were merged this time by the JavaScript/TypeScript team. Among these changes are improvements in performance of caches and File Structure view, reworked Rename refactoring (which can now rename files corresponding to TypeScript types), as well as support for TypeScript implementations and overrides in Find Usages.

TypeScript keywords var, let, and const are now resolved according to the types they reference. This means that you can Ctrl-click these keywords to go the corresponding type declarations or just hover the mouse over to learn what a keyword refers to.

ReSharper support for var, let, const in TypeScript

JavaScript/TypeScript formatter settings became much more granular. You can now specify the right margin for your code and define whether and how various code constructs should be wrapped. For example, you can specify where to place dots in multi-line chained method calls or you can opt for a ‘comma-first’ style for lists, object literals and function calls.

New features in JavaScript and TypeScript formatter

ReSharper 10.1 also brings initial support for Node.js. All ReSharper goodies you are well familiar with, like completion, code inspections, quick-fixes, and navigation features are now available for Node.js. However, we badly need your feedback on how ReSharper handles different things in your specific scenarios with Node.js.

ReSharper support for Node.js

dotPeek

For a long time, opening .nupkg files from disk was the only way to load assemblies from NuGet packages. In this dotPeek EAP build, you can try two more ways: find and load NuGet packages (and their dependencies if necessary) from any online package source, or load packages listed in a packages.config file in your Visual Studio project.

dotPeek: Loading assemblies from NuGet packages

Another handy improvement is that dotPeek automatically highlights usages of the symbol under the caret. We hope now that obfuscated identifiers will not get lost as easily in decompiled code.

dotPeek: highlighting symbol usages

dotMemory

All your navigation history through dotMemory profiling results is now recorded and you can quickly return to any view or diagram that you once opened using the browser-style Back and Forward buttons.

Back and Forward buttons for dotMemory

dotCover

Coverage filters, which let you ignore specific parts of your code when calculating coverage, are now supported in Continuous Testing.

Give it a try

Interested in the improvements described above? Please go on and download ReSharper Ultimate 10.1 EAP.

If you are experiencing any issues with the EAP, please report them to issue trackers of affected products: ReSharper, ReSharper C++, dotTrace, dotCover, dotMemory, dotPeek.

Posted in News and Events | Tagged , , , , , , , , | 15 Comments

Project Rider: subscribe to receive early builds as soon as they are ready

Remember Project Rider, that funky mix of ReSharper and the IntelliJ platform that makes up a new cross-platform C# IDE?

JetBrains Rider: text editor and quick-fixes

We’re actively working to start delivering builds that are good enough to be used outside JetBrains.

Meanwhile, we have just opened a form for you to subscribe to take part in Project Rider Early Access Program. To everyone who subscribes, we will be sending links to Project Rider builds as soon as they are ready.

Subscribe and hold on!

Posted in News and Events | Tagged , , | 6 Comments

ReSharper Ultimate 10.1 EAP Build 1 (Part 2)

The scope of improvements in the recently launched ReSharper Ultimate 10.1 EAP is so huge that the communications just don’t catch up with the development team anymore.

In the first part of an overview of the latest ReSharper Ultimate, we talked about an array of new context actions, refactorings, code inspections and quick-fixes.

This part 2 is less centered around C# support and lists more prominent improvements across languages supported by ReSharper, as well as considerable updates to other ReSharper Ultimate products: ReSharper C++, dotTrace and dotPeek.

ReSharper (continued)

Smart Paste

Smart Paste is a new feature that ensures the right escaping in string literals that you copy/paste around your code.

For example, you can copy a piece of text or XML that contains double quotes, paste it into a string literal in C#, and have ReSharper automatically escape all the quotes.

Smart-pasting XML into a C# string literal

This also works when you’re pasting a piece of C# code into an XML doc tag: Smart Paste will escape any generics and lambda syntax, as well as logical operators and anything else that is fine in C# but not allowed in XML values.

Other things that ReSharper can escape for you include file paths and line breaks.

The feature works in C#, VB.NET, JavaScript, XML, XAML and HTML files, making sure to respect the different ways of escaping illegal characters that are used in different contexts.

Initial support for JSON and JSON schemas

ReSharper 10.1 is expanding its technology reach by supporting JSON files and schemas in all supported versions of Visual Studio (2010-2015).

JSON and JSON schema support currently ranges from things as basic as syntax highlighting in older Visual Studio versions, to more sophisticated features like formatting and rearranging (for example, you can move object properties or arbitrary selections around), code inspections and quick-fixes, as well as code completion that is aware of schemas, paths, regular expressions and packages.

Regexp completion in JSON schema

JavaScript and TypeScript support evolves

ReSharper 10.1 brings initial support for experimental JavaScript syntax constructs that are projected to be part of ECMAScript 7. These include comprehensions, decorators, class properties, exponentiation operator, rest and spread properties for object literals.

In terms of TypeScript, ReSharper 10.1 EAP is highlighted by:

  • Support for TypeScript 1.7 that is (hopefully) complete
  • Experimental support for TypeScript 1.8 including string literal types

Other changes

Other notable changes in ReSharper 10.1 EAP 1 include:

  • Run configurations that are extended so that you can now attach the debugger to a running configuration
  • New code style settings and inspections to enforce style for braces and attribute sections
  • A quick-fix to convert a part of a loop to LINQ is now disabled by default (as it rarely produces a readable result), and a quick-fix to convert the full loop to a LINQ expression is downgraded to a hint
  • Correct detection of C# language level in .cshtml files
  • A new context action to add braces around switch case statements
  • Various fixes to existing quick-fixes such as “Encapsulate field” and “Change instantiated type”

Here’s the (presumably) full list of fixes in ReSharper 10.1 EAP 1.

ReSharper C++

Similar to the mainline ReSharper, ReSharper C++ 10.1 EAP introduces a substantial set of new context actions and quick-fixes. In addition, it adds To-do Explorer, improves the code generation subsystem, and supports more C++ language features.

To-do Explorer

ReSharper C++ 10.1 introduces the long-awaited navigation view: the To-do Explorer, which lets you view, group and filter comments that contain one of the 3 default to-do patterns (Bug, Todo and Not Implemented) and any custom patterns that you might want to set up.

Todo Explorer in ReSharper C++

If you use the full ReSharper Ultimate license and you have a multilingual solution, the To-do Explorer will gather to-do items from all supported languages: C#, VB.NET, C++, JavaScript, XAML, HTML etc.

An array of new context actions and quick-fixes

In most cases whenever there’s a code inspection, one or several quick-fixes should be available to alleviate a detected problem. With that in mind, ReSharper C++ 10.1 adds quick-fixes to some of its existing code inspections. Examples include:

  • “Create and initialize field from constructor parameter” is now available as a quick-fix to a code inspection that detects an unused constructor parameter:
    Quick-fix to create and initialize field from constructor parameter in C++
  • Whenever ReSharper C++ reports possible unintended object slicing, it now suggests a quick-fix to add an explicit cast.
  • If the type of a value that is actually returned doesn’t match the return type of a function, ReSharper C++ will suggest a quick-fix to change the return type:
    Quick-fix to change function return type in C++
  • If you are trying to assign to a read-only member, ReSharper C++ will now suggest to make the data member involved mutable:
    Quick-fix to make data member mutable in C++
  • If a base class or its function receives a final specifier, ReSharper C++ will put error highlighting over its overriding classes or functions and provide quick-fixes to remove the specifier
  • For any empty declaration that ReSharper C++ encounters, it will suggest a quick-fix to get rid of it

Other changes

Other notable changes in ReSharper C++ 10.1 EAP 1 include:

  • Rename refactoring can now rename files in addition to code symbols
  • The list of supported C++ language features is extended with generalized lambda captures (C++ 14) and exception specifications
  • The Generate stream operations action available via Alt+Ins can now generate stubs for Boost.Serialization functions: save(), load() and serialize()
  • Generate relational operators can now optionally use std::tie
  • Formatting options are now taken into account when generating code
  • All ReSharper C++ actions are banned from changing library headers
  • Code completion in C++ has undergone a massive bugfix, totaling around 50 resolved issues

Here’s the full list of fixes in ReSharper C++ 10.1 EAP 1.

dotPeek

Extension methods rendered as instance methods

For years, dotPeek has displayed extension methods as static method calls, often complexified with a legion of casts, all of which made extension methods hard to follow in decompiled code.

This update finally learns to show extension methods being called like instance methods, which makes for much more readable code.

Extension methods in decompiled code

You’ll notice from the screenshot above that dotPeek will only show extension methods as an instance method call if it is valid to do so. That is, QueryExtensions.SortBy is shown as an instance method call, but Queryable.Take and Queryable.Skip are shown as static methods, because there are other Take and Skip methods in scope that would make showing these as instance calls ambiguous.

As this change belongs to the decompiler core, it should apply in ReSharper’s integrated decompilation functionality as well.

dotTrace

Thread diagram in Visual Studio

dotTrace integrated in Visual Studio becomes a fully functional Timeline Viewer that allows you to perform detailed analysis of timeline performance snapshots right in Visual Studio.

Threads diagram, a part of dotTrace Performance Profiler integrated in Visual Studio

Before dotTrace 10.1, the main drawback of the integrated viewer compared to its standalone counterpart was the absence of the Threads diagram. This update removes the drawback: the integrated viewer gets exactly the same diagram, which you can now use to select threads, time range, and of course, view thread activity and filtered time intervals.

Other changes

dotTrace console utilities also get their portion of improvements. The reporter.exe tool used to get performance data from snapshots (e.g., for profiling automation and CI) now puts additional data in its XML reports. If you build a report with the /add_process_info option switched on, the report will include a path to the executable of the process that was profiled. This can be extremely helpful when profiling applications with multiple child processes.

There is also a number of minor improvements, such as updated colors in Timeline Viewer tables (it’s now easier to distinguish between table item states), and a more convenient grouping of snapshots in dotTrace Home.

dotMemory, dotCover

As of ReSharper Ultimate 10.1 EAP build 1, dotMemory and dotCover don’t include any significant updates apart from bug fixes.

Wrapping it up

Please download ReSharper Ultimate 10.1 EAP.

Experiencing issues with the EAP? Please report them to issue trackers of affected products. Here are links to issue trackers that you can use to report or track issues: ReSharper, ReSharper C++, dotTrace, dotCover, dotMemory, dotPeek.

Posted in How-To's | Tagged , , , , , | 3 Comments

ReSharper Ultimate 10.1 EAP Build 1 (Part 1)

Have you felt like it’s been all about Project Rider lately? Guess what, it hasn’t. We’ve been busy updating ReSharper Ultimate tools, and yesterday opened a new Early Access Program: ReSharper Ultimate 10.1 EAP 1 is now available for download.

This initial ReSharper Ultimate 10.1 EAP build accumulates a lot of changes across ReSharper and ReSharper C++; a few notable improvements in dotPeek and dotTrace; while changes in dotMemory and dotCover are so far limited to bug fixing and cosmetics.

Well, in fact, there are so many changes that this post only unveils those of them that relate to C# support in mainline ReSharper. Changes in support for other languages, as well as improvements to ReSharper C++, dotPeek and dotTrace will be described in a separate post later this week.

Anyway, please read on.

ReSharper

New context actions around strings

C# 6.0 as a whole and string interpolation in particular has been supported for a while, and this update adds a bunch of actions that help you switch between different ways of handling strings, such as interpolation, concatenation, and string.Format(), and makes sure all this is just an Alt+Enter away.

For instance, there’s now a context action to rewrite a string interpolation expression as a string.Format() call:
Convert to string.Format() call

Fancy string interpolation over concatenation? Alt+Enter will save you the effort of finding the right keys on your keyboard:
Convert string concatenation to interpolation

Gone way overboard experimenting with C# 6.0 features? No problem, ReSharper will detect whenever there’s nested string interpolation that should can be simplified:
Inline nested string interpolation

In some contexts, you just don’t need to use verbatim characters to differentiate identifiers from keywords. ReSharper can now point you at this kind of redundancy, and help you get rid of it locally or in a wider scope:
Remove redundant verbatim character

Other new actions around strings help:

  • Make a string equality check case-insensitive
  • Insert new arguments into string interpolation expressions
  • Use string interpolation expressions with various logger frameworks

New context actions to check argument values

Another group of context actions serves to generate checks upon method parameters based on their types:

  • For string parameters, ReSharper helps generate checks not only for nullness but for empty and whitespace strings
  • For numeric parameters such as int, double or decimal, ReSharper can write a check that ensures that only non-negative values are passed
  • For enum parameters, ReSharper generates a check that makes sure that an enum value being passed is in fact defined in the appropriate enum declaration, therefore guarding against ill-fated casts
  • Finally, for collection parameters, ReSharper helps set up a check against empty collections

Context actions to check parameter values

WCF-specific context actions, inspections and quick-fixes

Something clicked, and we’ve come up with a few inspections and actions that address some of the most common issues in WCF service development.

For example, whenever you have a WCF service method that is marked as [OperationContract(IsOneWay=true)] but it returns anything other than void or Task, ReSharper will spot this and suggest a fix to prevent a runtime error: you can either change return type to void or make the method two-way:

WCF quick-fix for a one-way operation that returns a non-Task type

If you have a [ServiceContract]-annotated interface that doesn’t have a single [OperationContract] member, then there’s something clearly going wrong: ReSharper will spot this and provide a quick-fix to annotate all members of the interface with [OperationContract].

Likewise, if you have methods marked as [OperationContract] in an interface that doesn’t have a [ServiceContract] annotation, ReSharper will spot this and suggest two options to resolve the issue:

WCF: containing type not marked as ServiceContract

Finally, there are new context actions to help you annotate all members in a [DataContract] type with either [DataMember] or [EnumMember] attributes. The longer your [DataContract] types are, the more you’re likely to appreciate this context action:

Context action to annotate WCF DataContract members with EnumMember

More new context actions and quick-fixes

There’s an assortment of new context actions and quick-fixes that can’t be classified as easily. These include:

  • A pair of context actions, one of which comments out a selection (effectively serving as an Alt+Enter equivalent of dedicated ReSharper shortcuts for commenting code), and the other uncomments whatever comment is under caret
  • A context action to delegate implementation of a non-implemented interface to a new field of the corresponding type
  • A pair of context actions to split or join attribute sections
    Context actions to split or join attributes
  • A context action to create another part of a partial type
  • A context action to add braces around switch case statements

Invert Boolean Member refactoring

When you modify a member that returns a boolean so that it gets an opposite meaning (say, refactor a method called IsNotAvailable() to IsAvailable()), you likely want to invert the value that it returns, and update other members that receive values from it.

This is what the new Invert Boolean Member refactoring can do for you. For example, by invoking it on a method, you can choose to rename the method and either invert values inside the method, and/or invert usages of the method.

Invert Boolean refactoring

The refactoring can be invoked on a method, property, local variable or a parameter.

More ReSharper improvements; changes to ReSharper C++, dotTrace and dotPeek…

…will be described in a follow-up post shortly.

What’s next?

Please download ReSharper Ultimate 10.1 EAP and make sure to put it to good use.

If you are experiencing issues with the EAP, please report them to issue trackers of affected products. Links to issue trackers that you can use to report or track issues are as follows: ReSharper, ReSharper C++, dotTrace, dotCover, dotMemory, dotPeek.

Posted in How-To's | Tagged , , , , , | 16 Comments