Pooling IBufferWriter

In the .NET 7 area some high performance APIs offer overloads for dealing with raw data via IBufferWriter<T>. IBufferWriter is a contract for buffered writing. High performance APIs typically offer an overload of their methods with IBufferWriter<T> along with byte[], Stream or Memory<T>. However, this is not the case for every API.

IBufferWriter<T> offers three methods:

  • GetMemory() and GetSpan() get a piece of writable memory.

  • Advance() to notify the buffer writer that data has been written.

.NET 7 offers two implementations of IBufferWriter<T>: Pipe (via PipeWriter) and ArrayBufferWriter<T>. Pipes help to solve the problem of parsing high performance streaming data. ArrayBufferWriter<T> offers an array-based buffering solution by implementing IBufferWriter<T>.

Find out more


Protobuf Source Generator

I have recently faced a challenge where significant amount of custom types had to be serializable with protobuf-net. A requirement for the task was to avoid attributing all properties with [ProtoMember]. A solution to this problem is using C# source generators to generate partial types with properties that are serializable. Such a source generator is described below and implemented in LaDeak.ProtobufSourceGenerator nuget package and GitHub project.

A source generator that generates partial helper classes where member properties are attributed with ProtoMember attribute for serialization with protobuf-net.

Getting Started

Install nuget package:

Find out more


Output Caching gRPC is Bad Idea

In this post I investigate how to enable ASP.NET Core's Output Caching for an ASP.NET Core gRPC service. Primarily, this is done for the sake of curiosity. The concept, design and code below should be avoided in production grade applications.

Output Caching

Output caching is a new type of caching introduced with ASP.NET Core 7.0. It positioned between response caching and in-memory (or distributed) caching. With output caching the server responses are cached on the server. However, it gives less flexibility on choosing custom keys or caching strategy compared to in-memory caching provided by .NET runtime.

Output cache varying allows caching based on keys composed from query parameters, header parameters or by chosen value given the HTTP request. While output cache provides features like cache revalidation and cache invalidation, in this post I will not explore them in detail. Output caching is typically used for caching Razor pages, static HTML content, etc. in GET and HEAD HTTP requests. The default output caching policy behavior bypasses caching responses for authenticated requests or responses that sets cookies.

Find out more


Required Keyword

C# 11 introduces a new keyword: required. This keyword can be applied onto fields or properties to make them required to be set during initialization. In this post I will focus on using required properties.

In the past developers could create init properties that could be set only at initialization time by the type's constructor or object initializer. However, the compiler did not require the developer to explicitly set a value to a property.

Required properties make object initializers issue a compiler error when the developer does not set a required property.

In this post I will explore the following topics for required properties:

Find out more


ASP.NET Core and Http2, Http3, gRPC

This post is a quick lap around using http2 and http3 and gRPC endpoints with ASP.NET Core.

ASP.NET Core's Kestrel host on .NET 7 supports hosting endpoints with http1, http2 and http3 protocols. We can host gRPC endpoints with ASP.NET Core both using http2 and http3.

The two questions I would like to answer:

  • can we host http2 without SSL?

  • how to invoke an http2 endpoint without SSL?

  • how http3 REST performance compares with gRPC over h2?

Find out more