ReSharper Ultimate 2016.2 EAP: Builds 7 and 8

ReSharper Ultimate 2016.2 EAP goes on, and we’ve recently published two more builds. Here is what has been fixed, and below are some new features in these builds.

Improvements in surround templates

We have been working towards merging live and surround templates as well as improving the availability of templates.

As of now, each non-file template can be used for generating code, for surrounding code, or for both, which lets you reuse your custom surround templates as live templates and vice versa, reducing their total count.

Another new thing here is that surround templates become available in the completion list, so you can start typing the name of a surround template as soon as a selection is made without pressing any additional shortcuts:

Surround templates in completion lists

The traditional way of invoking surround templates with Ctrl+E,U (ReSharper | Edit | Surround With Template) is also improved. The problem of too many templates in the Surround With pop-up, previously addressed with the editable ‘quick access list’, is now solved another way: while the pop-up shows all available templates, you can start typing a template name to shrink the list.

Marking language injections with comments

When a string literal contains a formal language, ReSharper can provide its code analysis and assistance features right inside this literal. Since v. 9.0, this has been available for regular expressions, and v. 2016.2 brings support for injected HTML.

Let’s recap how it works. As it’s impossible to automatically detect whether the formal language is intended in the literal, you have to mark the injection explicitly in one of the following ways:

  • Use the context action, which actually tells ReSharper to mark the symbol range corresponding to the string as Regexp/HTML, save this range in its internal database and keep track of it as the containing file changes. This way is very quick and straightforward, but there are two downsides: the range can be lost after an external file change, such as a VCS merge, and the injection marked this way will only be tracked locally.
  • Mark method parameters accepting regular expressions with RegexPatternAttribute from JetBrains.Annotations. This is the recommended way for regular expressions in parameters.
  • ReSharper 2016.2 introduces a third way: you can put a comment /*language=html|regexp|jsregexp*/ before the string literal. Granted, these comments require some typing and you can even think of them as contaminating your code. However, they make your intention clear to everyone who reads your code, they won’t get lost, and anyone opening your code with ReSharper will get the same features in the marked strings. By the way, the format of comments is compatible with IntelliJ Platform-based IDEs.
    Language injection with comments

More C# typing assistance

In addition to the smart behavior of dot and semicolon inside braces, which
we mentioned previously, ReSharper now automatically corrects mistyped @$ prefixes for verbatim string interpolations:

Generating abstract members in TypeScript

In TypeScript, you can now generate implementations for abstract members using either the Generate menu (Alt+Insert) or a quick-fix:

Generating abstract members in TypeScript

Please download the latest 2016.2 EAP build and give the new functionality a try. As usual, we would love to get your feedback via ReSharper issue tracker.

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

Rider EAP update: unit testing, .NET Core, and more

We recently (June 20) published a new private build of Project Rider, our standalone, cross platform C# IDE. We’re getting closer to starting the public preview, and so we’ve decided to start sharing details of the new features that are making it into the latest private EAP builds.

Obviously, previous EAP builds have had their fair share of new features, such as the File Structure view, Solution Wide Analysis, and the NuGet Explorer, as well as more fundamental architectural work, such as enabling inspections, the Alt+Enter menu, various refactorings and of course build and debug. We’ll take a look at some of these existing features in posts closer to the public EAP release, but for now, we’re going to start talking a bit more about what’s in the latest builds.

So, what’s new with the latest EAP?

As well as fixing a number of bugs (including some with the NuGet support), we’ve added some new things that we think you’ll like. Here are the highlights:

  • Unit test runner
  • ASP.NET Core support
  • To-do Explorer
  • Stack Trace Explorer

Unit Test Runner

The big news for this release is the addition of the unit test runner. This has been a very heavily requested feature, and we’ve worked hard to bring an initial version to Rider.

You should find the functionality very familiar if you’re already used to ReSharper. Rider has support for NUnit and xUnit by default. It does not currently support MSTest, as MSTest is too closely tied to Visual Studio.

Rider will discover tests in the editor, as you type, just like in ReSharper, and add a gutter icon to indicate test classes and test methods. You can either click this icon or use the Alt+Enter menu to run tests, which will be displayed in a test runner window very similar to the one in ReSharper.

Run tests from the alt enter menu

The tool window has multiple tabs, one for each session. The tab will show a tree view of the tests that are going to be run, with status icons to show pass, failed, skipped, etc. The output pane shows any output or failure messages, with the stack trace parsed and click-able for easy navigation. Double clicking the test in the tree will also navigate to the test method in the editor, and there is a toolbar to control running, stopping, deleting, grouping and so on.

Running tests

This is initial support, and there are still a number of features that we haven’t yet implemented, such as debugging, or more ubiquitous means of running tests. But don’t worry, we’re not done yet. We wanted to get this feature into your hands as soon as we could, so you can try it out, and let us have your feedback!

ASP.NET Core support

Rider uses ReSharper as an out of process language server, and is built from the same codebase that is the current 2016.2 EAP. This means it benefits from ReSharper’s support for ASP.NET Core projects, and can create new and open existing .NET Core projects. Furthermore, Rider includes project templates that allow you to create a new .NET Core executable or class library, so you can build your own projects from scratch.

Like Visual Studio, Rider requires existing projects to have both  .sln and  .xproj files; it doesn’t support opening a  project.json file directly. And of course, with the recent announcements that  project.json is being replaced by MSBuild  .csproj files, it is now very unlikely that we will implement this support only for it be obsolete in a few months time. If you have an existing project that only has  project.json, you can create a new project in a temporary folder and copy the  .sln and  .xproj files across and Rider will be able to open the project.

Once a project is open, Rider fully recognises the new style of referencing packages rather than assemblies, and the References node in the Solution Explorer will show packages and dependencies. Other functionality – smart editing, code completion, navigation and so on – just works.

We even get to take advantage of ReSharper’s advanced functionality, such as code completion and navigation for controller actions, and that includes from ASP.NET Core’s new tag helpers in  .cshtml files (oh yes, we support  .cshtml files too, with syntax highlighting, code completion, navigation, and even code completion and find usages on CSS classes).

Tag helper in code completion

To-do Explorer and Stack Trace Explorer

Another couple of new tool windows that we have added in this release are the To-do
Explorer and the Stack Trace Explorer.

The To-do Explorer works very much like you’d expect from ReSharper – scanning comments in your code that match // TODO: Fix this and pulling those out into IntelliJ’s own To-do Explorer tool window. Each item is shown as a node in the tree, grouped by file, and double clicking the item will take you to the line in the editor.

The To Do Explorer

Even better, we get to take advantage of existing IntelliJ functionality. From the Commit Changes dialog, if the Check TODO checkbox is selected, Rider will look for to-do items in the changes being committed, and allow you to review them – but only if it’s a new to-do item! The comment has to be in a block of text that has been changed.

Commit dialog checking for TODO items

The Stack Trace Explorer is simple, under the Tools menu, select Analyse Stack Trace. A new dialog opens that shows a simple text control, which shows the contents of the clipboard by default. Clicking OK on this dialog opens the Stack Trace Explorer, which parses the stack trace and makes each element clickable, so you can use it to navigate to any method or type in the stack trace.

Stack trace explorer


One thing to point out is that it’s not just updates to ReSharper that make it into Rider, but updates to the IntelliJ Platform, too. This build of Rider is based on a newer version of the IntelliJ Platform that gives new features over previous builds, such as improved log views for Git and Mercurial in the source control integration, and even font ligature support in the editor!

However, while it is nice to pull in the latest platform updates, this version of the IntelliJ Platform is still in EAP, which means some of the plugins in the default plugin repository are not yet marked as being compatible. For example, IdeaVim, which adds Vim emulation to the editor, requires an install of an EAP build, from an additional EAP plugin repository, as detailed in the readme.

As ever, please remember that this is still a private EAP build – we’re actively building the product and implementing features, and still require as much feedback as possible. Please try it out (if you haven’t already signed up, you can easily do so on the website), and let us know about any issues you encounter.

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

ReSharper Ultimate 2016.2 EAP: Builds 5 and 6

Another couple of ReSharper 2016.2 EAP builds has appeared since our last post. If you haven’t done it yet, it’s the right time to download and try out new features and fixes. In these builds, we have fixed a numbers of issues as we normally do, improved support for the recently released .NET Core 1.0 and ASP.NET Core 1.0, and below are descriptions of some new features.

HTML analysis inside .cs, .js, and .ts files

If you wanted to cut corners and define some constant piece of HTML right in a string literal, you could miss some errors there… but not any longer. In C#, JavaScript or TypeScript, you can now use the Make HTML here action to enjoy syntax highlighting, error detection and other HTML goodies right inside the string literal:

Injecting HTML inside a string literal

New decompiler features in ReSharper and dotPeek

  • The code that the IL Viewer displays becomes more readable: types, members, type parameters, local variables, etc. are highlighted with distinct colors; loops in your code can be distinguished by corresponding indents and comments:

    IL viewer with highlighting and formatted loops

  • The arsenal of visual dependency analysis tools (Type Dependency Diagram and Project Dependency Diagram) is now extended with the new Assembly Dependency Diagram. You can invoke it on selected assemblies in the Assembly Explorer and study how those and referenced assemblies are linked with each other:

    Hierarchy of assembly references

ReSharper C++

  • The latest 2016.2 EAP build includes an important optimization of C++ code analysis. For example, this optimization makes indexing (first opening) of the Unreal engine project several times faster.
  • Auto-completion in C++ now also suggests symbols that are not included in the current file. Of course, the corresponding #include directives are added automatically:

    Import suggestions in C++ auto-completion

  • There is a new code inspection that warns you about missing include guards in your header files. As a quick-fix, it lets you automatically add #pragma once directive.
  • And there are also a couple of new code formatting options: a line break in a member initializer list, and a space between closing angle brackets in template arguments (for conformance with pre-C++11 compilers).

You are welcome to download the latest 2016.2 EAP build. Should you come across any problems, please let us know in ReSharper, ReSharper C++ or dotPeek issue trackers.

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

ReSharper Ultimate 2016.2 EAP: Builds 3 and 4

In recent weeks, we’ve published builds 3 and 4 of the ReSharper 2016.2 EAP, and we have a lot to share with you, including a couple of new features, as well as the usual round of issues being fixed.

So, what’s new?


First up is continued improvement to our support for .NET Core RC2 projects, with a number of issues fixed.

Secondly is a new feature we’re formally calling Structural Navigation, but informally known as “Make Tab Great Again”.
Make Tab Great Again hat

The idea of this feature is to allow you to use the Tab and Shift+Tab keys to quickly move the text selection to the next or previous code element without having to use the cursor keys, allowing you to quickly navigate to the next important piece of code you need to edit.

For example, when editing a method call, repeatedly hitting Tab will select each argument in turn.

Structural Navigation navigating method arguments

Or when editing a  for statement, Tab will select the initialiser statement, then the terminating condition and then the iterator statement. Shift+Tab will do the same, but in reverse.

Structural Navigation navigating for loop elements

Of course, Tab will continue to handle template expansion, and will also indent (and Shift+Tab will outdent) when the text caret is placed at the start of a line. But when the text caret is placed with a code element, Tab and Shift+Tab will start navigating and selecting the structure of your code. You can change this behaviour in the options.

We really welcome your feedback on this feature – we’re finding it useful for quickly copying and altering code, or working with elements in string interpolation. This currently works with C#, HTML, XML and XAML as well as Razor files, and we’ll be adding support for other languages as the EAP continues.

SSR patterns can now be suppressed with a standard comment. A Structural Search and Replace pattern can be used to create your own ReSharper inspections, declaratively (see the web help for more details).

These highlights are treated just like ReSharper’s own inspections, with one big exception – until now, it’s not been possible to suppress an inspection with the standard // ReSharper disable once ... style comment.

EAP3 includes a new field in the SSR dialog, called “Suppression key” where you can specify the text that will be used and recognised in the comment.

Suppress SSR pattern with comment

C# support gets a number of new features:

  • Check all parameters of a method for  null (or empty strings) from a single Alt+Enter menu.
    Context action to add guard clauses for all arguments at once
  • You can now uncomment or even delete a comment straight from Alt+Enter.
    Uncomment or delete a comment from the Alt + Enter menu
  • We’ve added new quick-fixes for string literals containing invalid escape characters, to either replace with a verbatim string, or escape the characters.
    Quick-fixes for invalid characters in string literals
  • And interpolated strings get support for localisation, with a highlight to suggest converting the interpolated string to a resource, as well as both a quick-fix and a refactoring to automate the process.

Visual Basic gets some love:

  • String interpolation suggestions, quick-fixes and context actions for VB.NET to convert  String.Format method calls to string interpolation, as well as context actions to convert a string literal to an interpolated string, or insert an interpolated argument.
    Convert VB string concatenation to string interpolation
    Note that this requires  Option Strict to be enabled to ensure correctness of the converted expression.

And the JavaScript, TypeScript and JSON support gets updated:

  • TypeScript support gets a couple of fixes in this build, with the most notable being how we resolve definition files referenced by JSPM (RSRP-458759), by parsing details directly from calls to  System.config().
  • JavaScript rename refactorings will now update JSDoc items.
  • JSON value helpers allow you to tell ReSharper to provide code completion or validation for your own JSON files, either complementing an existing schema, or if the file doesn’t have a schema.
    You can add a helper in the JSON Value Helpers options page, matching based on a filename mask and/or schema match, and providing a path to the JSON property (such as /compilerOptions/rootDir), and the type of helper to apply – regular expression, file path or even license.
    Value helper options
    And then, in the JSON file itself, the value will now get code completion:
    Value helper showing code completion for a file path
    These value helpers are saved by default to the global settings, but using the Save To button in the options dialog, can be saved to a  .sln.dotSettings file that can be checked in and shared with the whole team.
  • Custom JSON schema catalogs can be added in the JSON options. These can be either a file, or a URL, which will be downloaded in the background, and periodically updated. More details can be found in the “Public API” section on
  • Another very useful fix in this version is the return of autocomplete of package version in bower.json files, for all versions of Visual Studio.Code completion for bower packages and versions

ReSharper C++

ReSharper C++ also gets a set of new features:

  • Support for C++14 language features: variable templates and  decltype(auto).
  • Warning about usages of classes and functions marked with the [[deprecated]] / __declspec(deprecated) attribute:
    ReSharper showing highlight for deprecated C++ code
  • Support for the [[noreturn]]/ __declspec(noreturn) attribute in control flow inspections.
  • A code inspection and a quick-fix to replace zero constant with false in boolean context:
    C++ code converting constant expression to boolean
  • New code style options that control the format of generated include directives.
  • Inline Variable refactoring:
    C++ inline variable
  • A new formatter option to allow single line function and lambdas.
  • The mock function generator now supports the Trompeloeil framework.
  • Support for completion, find usages and rename of symbols in doxygen comments.

As ever, please download a fresh build from the EAP page, and if you encounter any issues, please raise an issue in ReSharper or ReSharper C++ issue tracker.

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

Smart Tooltips in dotTrace 2016.1

If you’ve used dotTrace integrated in Visual Studio before 2016.1, you probably noticed its main drawback compared to its standalone counterpart. It lacked the fully functional Threads diagram. The only ability to select threads was to use the Threads filter that had no way of selecting specific time intervals, viewing threads activity, and so on.

dotTrace 2016.1 removes this drawback by adding the exact same diagram you are used to using in the standalone dotTrace Timeline Viewer.

Threads diagram in Visual Studio

But that’s not all! The Threads diagram in both standalone and Visual Studio viewers gets smart tooltips. Hover the mouse over a specific time point on the timeline to see a tooltip showing the current thread state, executed method, and other info. Tooltips are context-sensitive: if some filter is applied, the tooltip will contain additional data on the filtered event.

Use these new tooltips to visually examine the control flow of your application without digging into the call tree.

For example, when no event filters are applied, the tooltip will show only general data for the specific time point: the name of the method that was executed, class and namespace names, as well as thread state:

Smart tooltip

When you apply a filter, the tooltip will also contain info about the filtered event. For example, when you turn on the File I/O filter, the tooltip shows data on file operation, file name and data size:

Smart tooltip with enabled filter

Note that the tooltip also shows data on the filtered time intervals: the overall length of the highlighted interval and how many events it contains:

Smart tooltip with enabled filter

If you apply more filters, the tooltip will simply add their data to the list. For example, if you add the filter by Thread State, the tooltip will additionally show the CPU core data:

Smart tooltip with enabled filters


Note that data on the filtered time intervals at the top of the tooltip also gets updated:

Smart tooltip with two enabled filters

We hope you find this new feature useful. Do try it on your own by installing the latest dotTrace 2016.1 from the ReSharper Ultimate toolset.

Posted in dotTrace Tips&Tricks, ReSharper Tips&Tricks | Tagged , | 3 Comments

ReSharper Ultimate 2016.2 EAP: Build 2

Hello everyone. Last week we have published the second EAP build of ReSharper Ultimate 2016.2.

As usual, there are some fixed issues and a couple of new features:

  • Support of .NET Core RC2 projects, which means that ReSharper now correctly resolves project references and provides its core set of features (code inspections, code completion, navigation, search and refactorings) in projects of this type.
  • Speaking about support of different project types and problems that arise here, ReSharper 2016.2 brings a universal clue to the problem of unresloved project references. While previously it just showed tons of errors in the editor and red SWA indicator, it now notifies you as soon as some project references are unresolved
    ReSharper shows unresolved project references
    and allows to address this in two ways: either list all unresolved references to fix them manually or run MSBuild and obtain correct references that Visual Studio uses for compilation:
    ReSharper helps fixing unresolved references
  • ReSharper’s code inspections, code completion, navigation, search and refactorings are now also available for custom properties and variables in CSS:
    ReSharper supports custom properties and CSS variables.

If you encounter any issues with this EAP build, please report them to ReSharper issue tracker.

That’s it for today. Stay tuned however, because EAP builds that follow will bring much more new features.

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

Advanced course in dotMemory Unit

Some of you know one of our most recently released .NET products: dotMemory Unit, a unit testing framework that helps check your .NET code for memory issues.

In a nutshell, dotMemory Unit adds memory profiling to your unit testing framework. With dotMemory Unit, you can write tests that check your code for all kinds of memory issues, protect already fixed leaks from regression, and use the TDD approach when writing memory-consuming algorithms.

How is all this implemented? In this post, we would like to shed some light on the internals of dotMemory Unit.

If you need an overview of dotMemory Unit before diving in, start with this blog post that explains the basics, then take a look at some usage examples, or refer to online help.

Test methods

It’s all about tests. First of all, dotMemory Unit tries to detect which of your methods are tests. Why does it need that?

First, because you might want to decorate your test with a special attribute to tell dotMemory Unit what to do. For example, you can ask it to check the amount of memory traffic in a test with [AssertTraffic(AllocatedSizeInBytes = 300000)].

The second reason is that it needs to know exactly when each test starts and ends in order to save a memory snapshot if a test fails on a “memory” assertion.

For most unit testing frameworks, namely MSTest, NUnit,, MbUnit and csUnit, dotMemory Unit detects test methods automatically by injecting its calls into the beginning and the end of all tests.

Even if your unit testing framework of choice is not on the list of frameworks supported out of the box, you still can use dotMemory Unit. You can find more details on how to do this later in this post.

Why use lambdas in dotMemory.Check()

In order to get memory state and make assertions you should write something like this in your test:

Why do we need a lambda as an argument of the dotMemory.Check() method to do such a simple thing? There are several reasons for this.

First, you don’t need to write a special “memory test” to detect memory issues, it is enough to add an assertion on memory state to your regular unit test.[1] Such a test (checking both memory and logic) can be run under dotMemory Unit or as an ordinary test. In the latter case, the test will fail as there’s no valid memory data. And this is exactly why we need dotMemory.Check(): the lambda passed into this method will not be called at all if tests are running without dotMemory Unit.[2]

The second reason of having a lambda as an argument in dotMemory.Check() is to know whether a test failed on checking memory state or on checking business logic: it is useful to have snapshots from tests failed on checking memory to go straight to memory problems.

  1. There is an example of such tests (see RemovePetriDish test). It is a normal unit test, checking that there are no items in a collection after removing the last item, but it also checks that there are no items retained in memory, which means no memory leaks.
  2. By default, if dotMemory.Check() is called without dotMemory Unit, it will fail. If you need the test to pass by ignoring dotMemory.Check(), mark the method, class or assembly with the attribute [DotMemoryUnit(FailIfRunWithoutSupport = false)]

Using dotMemoryApi instead of dotMemory.Check()

dotMemory.Check() is suitable for most common simple cases but if you don’t like its syntax or find it unsuitable for any other reason, rest assured there’s an alternative available.

In the following example, dotMemory.Check() looks out of place when memory usage data is gathered during the test and checked just once in the end:

What is the other option? At the heart of dotMemory Unit, there’s the dotMemoryApi class, which is quite simple:

The above example can be rewritten using dotMemoryApi as follows:

But how do we tell dotMemory Unit to save snapshots if a test failed on a memory assertion? Of course, you can use the “save on any fail” auto-saving strategy, but it is not always convenient. Let’s write a single method that uses a lambda as well but looks not as awkward as in the initial example…

…and rewrite the assertion block from our last example:

This call will save a workspace with memory snapshots in case of a failure. As an added bonus, it just looks neat, doesn’t it?

Let’s take a closer look at DotMemoryUnitController and see how it can be useful when dealing with testing frameworks that aren’t supported out of the box.

Unsupported testing frameworks

What should you do if your favorite unit testing framework is not supported by dotMemory Unit out of the box? The answer is, adapt it manually! In fact, all you need is to tell dotMemory Unit where your test method starts, ends and fails. All this can be done using a single DotMemoryUnitController class:

To make it easier and more elegant, you can write your own wrapper or use this one. At the end, your test will look like this (even attributes will work fine):

Although DotMemoryUnitController is mostly designed for unsupported testing frameworks, it also can be used in combination with dotMemoryApi to achieve behavior similar to the dotMemoryUnit.AssertBlock() example above.

More ways to tune

There are many ways how you can fine-tune dotMemory Unit to your liking. For example, if you don’t like the lambda in the GetObjects() method, you can write something like this:

and then completely avoid lambdas in your tests:

Also, don’t miss QueryBuilder. This powerful tool allows creating reusable queries to make your tests more maintainable. For example, we can rewrite one of the examples from this article using QueryBuilder to avoid code duplication:

If you’re using core classes dotMemoryApi, DotMemoryUnitController and QueryBuilder and have a general idea of how dotMemory Unit works inside, you can customize almost everything and write your perfect framework.

Whether you want to go that far or you use the default framework, dotMemory Unit will help you replace time-consuming manual profiling with automated memory tests.

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

ReSharper Ultimate 2016.2 EAP kicks off

Welcome to ReSharper Ultimate 2016.2 Early Access Program!

Here’s a quick summary of what is available in the initial EAP build:

  • Initial support of ASP.NET Core 1.0 RC2, including support for tag helpers in terms of code completion, navigation, search and refactorings. At this point, ASP.NET Core web applications are supported if they’re targeting .NET Framework but are not supported if they’re targeting .NET Core. We’re looking to improve this in subsequent builds.
  • Assorted TypeScript support improvements such as generative code completion; improved Find Usages and Rename for union and intersection types; more TypeScript 2.0 features (this types for functions, control flow-aware type guards, path mappings, optional class members, the never type); important bug fixes for Angular and Sugar users.
  • Multiple bug fixes and better spec handling in CSS support, which is expected to improve code validation and completion.
  • A new refactoring to move members to another part of a class. You can even use the refactoring over a region to move all region members into a new file with a name inferred from the region name.
    Make partial class refactoring
  • New quick-fixes and context actions, helping simplify string interpolation inserts, revert the order of iteration in simple for loops, or fix awaiting of a void method by making it return Task. In addition, existing quick-fixes that make methods async now suggest to use Task instead of void.
  • Optimize References and Remove Unused References now allow marking references as used at runtime, which finally makes both features useful in solutions that are using IoC.
  • New subtle C# typing assistance features, such as auto-replacing MethodName(.) with MethodName(). as you type:

  • A revised indenting engine in the C# formatter, particularly new options for indenting parenthesis.
  • Rearrange code improvements. For example, it is now available in interpolated string inserts, and in expressions with 3 and more operands.

Changes are currently limited to the mainline ReSharper. Other tools such as dotTrace and ReSharper C++ will be merging their changes as the EAP goes forward.

Download ReSharper Ultimate 2016.2 EAP!

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

Open sourcing ReSharper’s external annotations

We recently open sourced the external annotations that ReSharper uses to improve analysis and provide extra features over third party code, and we’ve also opened up to contributions from the community. You can now add other assemblies, fix issues with the existing annotations, or simply make use of the information in the files.

But wait, what are external annotations?

ReSharper can use attributes defined in the JetBrains.Annotations nuget package to improve its own analyses and inspections – this blog post has more details. They can give ReSharper extra context to allow for more accurate inspections.

For example, if a parameter or return value can never return null, ReSharper can tell you that your null checks are irrelevant, and provide quick-fixes to remove them. Or perhaps you have a custom attribute that indicates that the method it’s applied to is only called by reflection – ReSharper will normally mark the method as unused, unless the custom attribute is itself marked with the [MeansImplicitUse], in which case ReSharper will mark it as in use.

ReSharper marking null analysis as redundant

Annotations are not just limited to improving inspections. For example, the [StringFormatMethod] attribute marks a method as having semantics similar to string.Format. When ReSharper sees this, it will treat the specified argument as a format pattern, and ensure that the right number of parameters are specified in the rest of the method call, and highlight the appropriate argument when the text caret is on the corresponding {0} format specifier.

Similarly, the [RegexPattern] attribute will mark a parameter as being a regular expression, and any string literal passed in will be syntax highlighted, have auto completion and Alt+Enter quick-fixes to test the regex.

String highlighted as regular expression

There are many more annotation attributes, and you can find out more details in the ReSharper web help, along with a reference for the available attributes.

These attributes are great for adding to your own source code (and they don’t even add any binary references!) – but what about pre-compiled assemblies? How to add these attributes when the code is already compiled? Well, that’s exactly what external annotations do.

An external annotations file is an XML file that ReSharper reads to effectively “add” attributes to existing compiled code. Each file describes types and type members in an assembly, and provides the fully qualified name for attributes to apply, as well as arguments for the attribute constructor (remember, when compiled, attribute constructor arguments are simply constants, serialised into the assembly).

When ReSharper reads the annotations file, it merges these “fake” attributes from the XML file with the real attributes from the assembly itself. As far as ReSharper is concerned, it’s as though the assembly was compiled with these attributes all along! This allows us to add [NotNull] and [CanBeNull] or [RegexPattern] attributes to a compiled assembly, and improve ReSharper’s analysis and feature set for existing code.

The external annotations that ship with ReSharper cover the entire BCL of the .NET framework, and more. We have performed null analysis on the whole BCL, and the results are applied to assemblies, types and type members. On top of that, we have added extra annotations for extra functionality – string format methods, regular expressions, ASP.NET Views, Actions and Controllers, and so on.

For the most part, the annotations are for BCL and related Microsoft assemblies, such as ASP.NET MVC, but certain third party assemblies are also annotated. Primarily, these are commonly used assemblies that benefit from a piece of functionality that the annotations can add. For example, various community MVVM frameworks are annotated with the [NotifyPropertyChangedInvocator] attribute to provide improved INotifyPropertyChanged support. Similarly, NUnit and are marked to contain assert methods, which ReSharper can use to help control flow analysis (e.g. if an assert is always going to cause an exception, we can mark the rest of the method as dead code).

And now, these annotations are open source. They’re available on GitHub, with an MIT license. We use this repo to build the annotations that ship with each version of ReSharper, and we’re opening it up to contributions from the community (we’ve already accepted a pull request to add support for FakeItEasy). If you see a mistake with ReSharper’s null analysis, or missing string.Format highlighting, raise an issue, or file a pull request. If you’d like to add a new third party assembly, fork the repo and add it!

And the best bit? Since version 10, ReSharper will automatically keep the annotations up to date. ReSharper 9 shipped them as a bundled plugin, and will prompt you to update them. This allows us to update some functionality without waiting for a full ReSharper release (as an example, an ASP.NET MVC update caused ReSharper’s navigation between views and controllers to stop working. The fix was to update the annotations to support the new version of the assembly).

But what this means now is that if a fix or new assembly is contributed, we can push the new version of the annotations to ReSharper 9, 10 and 2016.1.

Previously, external annotations could be shipped either side-by-side with an assembly (as a file called MyAssembly.ExternalAnnotations.xml) or as part of an extension. This still works, and if you have an existing ReSharper extension that adds features via a plugin .dll, it’s still a good idea to ship the annotations with the extension. But if the extension is just annotations, then it can be added to the standard annotations package, and we can make sure that all ReSharper users get it.

Check out this web help page for more details on how external annotations work, and what the file format looks like. This page lists all the annotations that are available. And finally, here’s the GitHub repo.

Posted in How-To's, ReSharper Tips&Tricks | Tagged , , | 4 Comments

dotMemory Unit update: version 2.3

Following a recent ReSharper Ultimate bug fix release, we are now releasing an update to dotMemory Unit, the .NET unit testing framework to check your code for memory issues.

As a reminder, dotMemory Unit lets you extend NUnit, MSTest, or another .NET unit testing framework with the functionality of a memory profiler. It’s integrated with Visual Studio, works with standalone unit test runners, can be used in Continuous Integration, and is free of charge.

Highlights of dotMemory Unit 2.3

Most changes in dotMemory Unit 2.3 relate to how dotMemory Unit works with unit testing frameworks that are not supported out-of-the-box. For example, new arguments are now supported in DotMemoryUnitController‘s methods:

  • The TestStart() method now accepts an instance of the MethodBase type: TestStart(MethodBase testMethod). You can use it to remove ambiguity and clearly specify a certain method as a test. For an example of using this method, see Working with unsupported unit testing frameworks.
  • The TestFailed method now accepts a bool parameter: TestFailed(bool onMemoryAssert). Use it to indicate whether a test failed on “memory” assertion or due to a different reason.

In addition, dotMemory Unit 2.3 improves how you check memory traffic in tests. You can now place any number of AssertTraffic attributes before the test and filter traffic by any set of conditions. For example, to ensure traffic doesn’t exceed 1000 bytes and there are no objects of the Foo type, simply add two attributes before the test:

For the detailed list of improvements in this dotMemory Unit update, please see dotMemory Unit 2.3 Release Notes.

Start using dotMemory Unit

You can download dotMemory Unit and start playing with it right away, or you can read the blog post that explains the basics, then take a look at some usage examples, or refer to online help for more detail.

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