Getting Started with Visual Studio 2017 v15.3

Microsoft has just released a round of major updates to the .NET stack. Visual Studio 2017 gets its biggest update yet. C# gets its first update to C# 7.1 as part of the faster release cadence enabled by Roslyn. The new open source frameworks .NET Core and ASP.NET Core both get their 2.0 releases and .NET Standard 2.0 has arrived to unify everything.

Over the last 16 hours I've been …

Read More

Maximizing Throughput - The Overhead of 1 Million Tasks

I recently needed to choose between two competing designs: a simple one that needed millions of tasks or a complex one that needed only a few processing threads.

Plan A was to leverage the power of Task-based asynchronous programming in .NET to create a simple solution that had tasks waiting on a mix of other tasks, timers, events, and more; but, it would need millions of tasks, all …

Read More

Better Benchmarking with Additive and Multiplicative Baselines

In my recent blog posts I've been benchmarking different ways to cast in C#. If you have a keen eye, you may have noticed that the results do not match up. In one experiment, a direct cast (no cast at all) takes 15ns, while in another experiment, a more complicated generic cast

Read More

Covariant and Contravariant Casting is 3x Slower than Dynamic

Previously, we saw that covariant and contravariant casting is slow: 100x slower than normal casting. It turns out that covariant and contravariant casting is even slower than casting to dynamic and using dynamic dispatch: 3x slower than dynamic. This is significant as IEnumerable<T>

Read More

Casting to IEnumerable<T> is Two Orders of Magnitude Slower

Casting to generic interfaces that use covariance or contravariance is two orders of magnitude slower than normal casts in C#. This means casting to IEnumerable<T> is two orders of magnitude slower too. This result was quite unexpected and very surprising.

In this post, I investigate the cost of casting to implementations, interfaces, generic interfaces, covariant …

Read More

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