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 , | 5 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 , , | 21 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

ReSharper Ultimate 2016.1.2 is here

We have just released a fresh bug fix update to our tools and welcome you to download ReSharper Ultimate 2016.1.2.

Major highlights

dotCover, dotTrace, dotMemory and dotPeek 2016.1.2 are updated solely for compatibility reasons and don’t include significant changes.

In case you were affected by the issues mentioned above, we recommend that you download and install ReSharper Ultimate 2016.1.2.

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

ReSharper Ultimate 2016.1.1 is released

You can now download ReSharper Ultimate 2016.1.1, which includes a set of bug fixes and improvements to ReSharper and ReSharper C++.

Highlights of this update

Note that dotCover, dotTrace, dotMemory and dotPeek 2016.1.1 are basically all compatibility updates that have not received any considerable changes by themselves.

If you are interested in the improvements described above, please download and install ReSharper Ultimate 2016.1.1.

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

JavaScript support improvements in recent ReSharper releases

There are quite a few things in ReSharper 2016.1 designed to advance your JavaScript experience.

This update improves support for JSX, enhances regular expression features, supports more complex type annotations and constructs in JsDoc, provides full-featured JSON and JSON schema support, and supports a lot of experimental ECMAScript features.

Also worth noting is official support for NodeJS, meaning that all your NPM package dependencies and node modules are now handled nicely.

Advanced JSX experience

JSX is a very popular ECMAScript extension that allows you to use XML-like syntax for JavaScript expressions. JSX is primarily used with the ReactJS framework, though not necessarily limited to it.

Earlier in ReSharper 10 we introduced initial support for JSX by providing all the features you usually expect from HTML in JSX tags.

JSX support in ReSharper

Because JSX markup can embed JavaScript code, expect to have usual assistance for JavaScript inside JSX, too.

JavaScript inside JSX

Starting with ReSharper 2016.1, if you use plain JS files in Visual Studio or use Visual Studio versions earlier than 2015, ReSharper now provides its own syntax highlighting for JSX constructs, so that you won’t even notice that your Visual Studio version is not the most bleeding-edge one. (You will however need to disable Visual Studio’s own syntax errors to have the best possible experience in this case.)

Improved support for JS regular expressions

Earlier in ReSharper 10, we extended our support for regular expressions in JavaScript by automatically injecting them into RegExp constructor and regex-related String methods (search and match). You can complete regex flags in RegExp constructor as well.

JavaScript regular expressions

Also, you can enjoy having a context action for injecting regular expression facilities into any JavaScript string.

Injecting regular expressions into JavaScript strings

Enhanced JSDoc support

JSDoc is supported for documentation purposes since ReSharper 9.1.

ReSharper 10 offered extended JSDoc support by using types specified in JSDoc for improving our existing features, such as code completion. Most of the types defined by JSDoc 3 were supported, including primitive types, union types, signatures, record types, type definitions, and callback definitions.

ReSharper support for types defined in JSDoc 3

ReSharper 2016.1 goes further as it supports templates (generics) and type inference for them, improves rendering for JSDoc that uses HTML tags, and supports structured parameter and property syntax.

ReSharper supports JSDoc generics

Also note that now all the JSDoc keywords are supplied with a short description of their meaning.

JSDoc tooltips

JSON and JSON schemas

Starting with ReSharper 2016.1, JSON is an officially supported language. That means that you get the usual ReSharper features in JSON files like typing assistance, formatting, rearrange code, and code analysis with quick-fixes.

ReSharper quick-fix in JSON

If your JSON file is supplied with a JSON schema, then you’ll be provided with code completion based on schema, and your JSON will be validated against the schema, providing fixes for validation issues.

JSON schema-aware code completion

Invalid JSON and a quick-fix

For several known JSON schemas, you get enhanced features such as regular expressions support, JSON Path references, file and folder references and completion for them, and code completion for packages (NPM, Bower and NuGet).

Code completion for known JSON schemas

As a special bonus, completion for open source license names in SPDX format is provided for NPM and DNX package descriptions.

Completion for Open Source license names

Note that all provided features are available for all supported Visual Studio versions.

ECMAScript Experimental

ReSharper 2016.1 provides initial support for most of the currently known ECMAScript experimental constructs (some of which are going to become part of the ECMAScript 2016 specification while others are still in proposal).

Now you can easily code with ReSharper while using transpilers such as Babel or when using ReactJS with ES2016 elements. Support is provided for: async functions and await, comprehensions, exponentiation operator, rest in object destructuring and spread in object literals, bind operator, class properties, decorators, new export statements, and call-constructors.

Experimental ECMAScript support in ReSharper

Node.JS support

ReSharper 2016.1 now fully supports working with Node.JS modules and NPM packages. This results in enhanced code assistance, in particular, better code completion and inspections when you use Node.JS modules.

Get ReSharper Ultimate 2016.1

We hope you enjoy these features when working with JavaScript. Do let us know about your experience with that by leaving a comment below.

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

JetBrains joins the .NET Foundation

Recently at BUILD, Microsoft announced that JetBrains has joined the .NET Foundation, which you can read more about on the .NET Foundation Blog. What we’d like to comment on in this post is the reason behind this decision.

Why join?

It’s no surprise that we have invested a lot in .NET as a platform, and thanks to a wide recognition by our customers, ReSharper and the ReSharper Ultimate suite have enjoyed tremendous success for over a decade.

With the recent announcement of JetBrains Project Rider, our cross-platform .NET IDE, we have increased our commitment to the the platform and are striving to provide a truly cross-platform experience for .NET developers that brings the functionality of ReSharper to all, whether working on Windows inside Visual Studio, outside of Visual Studio, on Linux or on OSX.

Given this investment, for us, the future of .NET as a platform is important and our participation in the Technical Steering Group is to this effect. In essence, we’ll have a voice (technically with three seats we have three voices!) in decisions that impact key projects of the .NET Foundation such as the CoreCLR, Mono, C#, ASP.NET et al.

Our commitment to ourselves and our customers is that we will strive for the best interests of .NET, which are to be a truly open, versatile and cross-platform ecosystem.

Posted in How-To's | 15 Comments