How to fix Fatal Error with Git in Visual Studio 2017

Every update I've applied to Visual Studio 2017 has broken Git again. Until 15.1 (26403.0), the solution was to delete Visual Studio's version of Git and let it pick up the version installed in Windows. I documented this in my post on troubleshooting the Visual Studio 2017 upgrade.

The problem manifests itself when you …

Read More

C# 7: Micro-Benchmarking the Three Ways to Cast Safely

As we saw in my previous post, there are three ways to cast safely in C# 7. In this post, I micro-benchmark the three methods of safe casting and dive into the IL to understand the differences.

The three methods of safe casting (from my previous post

Read More

C# 7: Is Operator Patterns - You won't need 'as' as often

C# has long supported two operators to check the type of an object: is and as. C# 7 adds a new way to use the is operator that combines is with basic patterns to provide an alternative for as.

The new is patterns provide a nicer syntax for safe casting than both the existing is and as

Read More

Cannot Go To Definition on Generic Types in VS2017

Go To Definition in Visual Studio 2017 has been bugging me for a while now. When I try to Go To Definition on some types, VS2017 pops up with an error "Cannot navigate to the symbol under the caret". Today, I decided it was time to try and figure it out.

This is not the first time this has happened and there are lots of people who experienced a similar error on VS2015. …

Read More

C# 7: Ref Returns, Ref Locals, and how to use them

C# has always supported the ability to pass by reference using the ref keyword on method parameters. C# 7 adds the ability to return by reference and to store references in local variables.

The primary reason for using ref returns and ref locals is performance. If you have big structs, you can now reference these directly in safe code to avoid copying. Before C# 7 you had …

Read More

C# 7: Dynamic types and Reflection cannot access Tuple fields by name

Tuples are a great new feature in C# 7 and I've used them a few times already. The syntax is great, they're easy to use, and they're a whole lot better than the alternatives.

Tuples are implemented using ValueTuple, with name erasure at runtime

Read More

C# 7: Local Functions are Funcs too

Local functions in C# 7 are versatile: they can be passed as Func<> and Action<> to other methods and they can be defined using the inline expression bodied syntax.

Because local functions are compiled into static methods, you should be able to pass them to any method that requires a Func<> or Action<> and sure …

Read More

C# 7: Dissecting Local Functions to understand how they capture local variables

One of the new language features in C# 7 is local functions. This feature lets you define functions within the scope of other functions. The main benefit of local functions is encapsulation and a secondary benefit is that they bring local variables into scope.

Although local functions appear simple, their interaction with other language features quickly leads to questions. I wondered …

Read More

How to set a custom Code Analysis Rule Set on an ASP.NET Core project

If you want to set a custom code analysis rule set on an ASP.NET Core project, there is currently no UI tooling in Visual Studio 2017 to support this scenario. However, you can add it manually to the csproj file.

To set a custom code analysis rule set on an ASP.NET Core project, right click on the project in solution explorer, select Edit <YourProjectName>.csproj

Read More

Favorite features in Visual Studio 2017

Visual Studio 2017 is now available, download it here. I've been converting my projects over to VS2017 and wanted to share my favorite features of the new IDE.

My favorites are Go To All, move type to matching file, string splitting, and coding conventions via EditorConfig. Other notable mentions are the overhauled Find All …

Read More