OpenAPI document generation in .NET 9
by Mike Kistler
posted on: November 25, 2024
Introducing the New OpenAPI Document Generation Feature in .NET 9. Let's take a look at what it is, how to use it, and how it streamlines API development in .NET.
by Mike Kistler
posted on: November 25, 2024
Introducing the New OpenAPI Document Generation Feature in .NET 9. Let's take a look at what it is, how to use it, and how it streamlines API development in .NET.
by Gérald Barré
posted on: November 25, 2024
While nuspec files are not as common as they used to be, they are still used in some projects when you have special needs. For instance, Meziantou.DotNet.CodingStandard uses a nuspec file to create a package that supports all TFMs. Renovate is a tool to keep your dependencies up-to-date. It support
by Sayed Ibrahim Hashimi
posted on: November 20, 2024
Introducing a new command line tool dotnet scaffold, a new interactive way to create projects in .NET.
by Andrew Lock
posted on: November 19, 2024
Understanding cross-origin security headers - Part 1
by Mika Dumont
posted on: November 18, 2024
Learn how to get started with GitHub Copilot for .NET development for AI assisted development in Visual Studio and Visual Studio Code
by Gérald Barré
posted on: November 18, 2024
In a recent post, I shared how to highlight C# code in string values. Roslyn provides more built-in highlighters / code-completions in string values. Most of the supported languages are available as constants of the StringSyntaxAttribute class. To indicate the language, you can use the lang or lang
by Oren Eini
posted on: November 15, 2024
In RavenDB, we really care about performance. That means that our typical code does not follow idiomatic C# code. Instead, we make use of everything that the framework and the language give us to eke out that additional push for performance. Recently we ran into a bug that was quite puzzling. Here is a simple reproduction of the problem:using System.Runtime.InteropServices; var counts = new Dictionary<int, int>(); var totalKey = 10_000; ref var total = ref CollectionsMarshal.GetValueRefOrAddDefault( counts, totalKey, out _); for (int i = 0; i < 4; i++) { var key = i % 32; ref var count = ref CollectionsMarshal.GetValueRefOrAddDefault( counts, key, out _); count++; total++; } Console.WriteLine(counts[totalKey]);What would you expect this code to output? We are using two important features of C# here:Value types (in this case, an int, but the real scenario was with a struct)CollectionMarshal.GetValueRefOrAddDefault()The latter method is a way to avoid performing two lookups in the dictionary to get the value if it exists and then add or modify it. If you run the code above, it will output the number 2. That is not expected, but when I sat down and thought about it, it made sense.We are keeping track of the reference to a value in the dictionary, and we are mutating the dictionary.The documentation for the method very clearly explains that this is a Bad Idea. It is an easy mistake to make, but still a mistake. The challenge here is figuring out why this is happening. Can you give it a minute of thought and see if you can figure it out?A dictionary is basically an array that you access using an index (computed via a hash function), that is all. So if we strip everything away, the code above can be seen as:var buffer = new int[2]; ref var total = ref var buffer[0];We simply have a reference to the first element in the array, that’s what this does behind the scenes. And when we insert items into the dictionary, we may need to allocate a bigger backing array for it, so this becomes:var buffer = new int[2]; ref var total = ref var buffer[0]; var newBuffer = new int[4]; buffer.CopyTo(newBuffer); buffer = newBuffer; total = 1; var newTotal = buffer[0]In other words, the total variable is pointing to the first element in the two-element array, but we allocated a new array (and copied all the values). That is the reason why the code above gives the wrong result. Makes perfect sense, and yet, was quite puzzling to figure out.
by Kathleen Dollard
posted on: November 14, 2024
Let's take a look at C# 13's new params collections that make methods easier to use and allow new optimizations.
by RNDr. Tomáš Grošup, Ph.D.
posted on: November 14, 2024
Read about latest F# 9 feature, Nullable Reference Types
by Aaron Powell
posted on: November 13, 2024
Learn about the .NET Aspire Community Toolkit, a collection of tools and libraries that help you build with .NET Aspire.