Blog Posts with tag ".NET"

From ASP.NET Core to Hugo: My Blog's Migration to Cloudflare

From ASP.NET Core to Hugo: My Blog's Migration to Cloudflare

Like many developers, my blogging journey started with WordPress. More than 20 years ago. It was convenient, widely supported, and quick to set up. But over time, the drawbacks began to pile up: security issues, constant updates, performance tuning, plugin juggling, costly – the overhead was real. I wanted something more streamlined, something that gave me control without stealing my time.

Read Blog Post
Task.Run vs. TaskFactory.StartNew

Task.Run vs. TaskFactory.StartNew

When working with asynchronous or parallel code in C#, you’ll inevitably encounter two common ways to start tasks: Task.Run and TaskFactory.StartNew. At first glance, they seem similar - but they behave differently and should be used appropriately depending on the context.

Read Blog Post
Standardizing AI Context: the Model Context Protocol

Standardizing AI Context: the Model Context Protocol

The Model Context Protocol (MCP) server acts as a centralized context management backend for advanced AI applications.

Unlike traditional session or prompt-based approaches, the MCP server manages a persistent, structured context that can be queried, updated and synchronized across distributed AI components and user sessions. By providing a standard API for serializing, retrieving and sharing context, the MCP server enables seamless interoperability between different models, services and clients. This is particularly important in multi-agent systems, long-running workflows or environments where state continuity and context portability are required.

Read Blog Post
When to use records in C#

When to use records in C#

For several years now, C# has supported Records as a new “type”. Initially only for classes (which is why the class is optional for a record class), later also for structs. Records are specially designed for use as data containers aka DTOs (please dont use DTO in your class name!). They are immutable and have special semantics for equality.

Read Blog Post
Increase Command Timeout for EF Core Migration Bundles

Increase Command Timeout for EF Core Migration Bundles

EF Core Migration Bundles are standalone executable files that contain one or more Entity Framework Core migrations and can be applied directly to a database. They are particularly useful for deploying migrations independently of the source code or development environment, e.g. in production environments.
Using migration bundles simplifies the deployment process as no additional software or configuration is required to perform the migrations. In CI/CD systems like Azure DevOps in particular, they can be executed across all platforms on all operating systems and therefore offer a flexible alternative to DACPAC deployments , which are often dependent on Windows tooling.

Read Blog Post
Auto Format your Code on save with Visual Studio

Auto Format your Code on save with Visual Studio

Code formatting is a very important element when developers work together on a project - and you are always well advised not to invent your own formatting rules, but to use those that are a standard or de facto standard in the respective programming language.
In C#, many rules are now controlled via the editorconfig , but there is still a lack of standardized formatting tools in .NET - dotnet format simply does not support many things - so that different functionalities exist in different IDEs (Visual Studio , Visual Studio Code, Rider).

Read Blog Post
Sustainable Code with .NET 9

Sustainable Code with .NET 9

Sustainable Code is a constantly growing GitHub repository created by me , in which I collect various everyday code snippets and measure the performance of the different implementation ways.
The goal is to create a collection of code that virtually everyone has in front of them every day and can thus easily implement the best way for themselves and their use case.

Read Blog Post
How to process ZIP Files from a Stream in .NET

How to process ZIP Files from a Stream in .NET

When working with ZIP files in .NET, there may be cases where the file is not stored on disk but comes directly as a Stream. This could happen if you’re downloading the ZIP file from a network, receiving it via an API, or working with in-memory file data. In this blog post, I’ll show you a simple example of handling ZIP files using streams in .NET and how to process their content without saving the ZIP to disk.

Read Blog Post
Decompress a ZIP archive with .NET

Decompress a ZIP archive with .NET

Working with compressed files is common in many applications, whether you’re extracting data from an archive, installing software packages, or retrieving bundled files. Thankfully, .NET finally provides an efficient, straightforward way to decompress ZIP files using the System.IO.Compression namespace. In this post, I’ll walk through a simple code snippet that you can use to decompress ZIP files in your .NET apps.

Read Blog Post
Efficiently clean a string with .NET

Efficiently clean a string with .NET

Strings are one of the most commonly used types in .NET applications - and very often the source of inefficient code. For example, cleaning up a string - such as removing invalid or non-visible characters - is one of the most common use cases for user input. Unfortunately, the most convenient, but not the most efficient, implementation imaginable is used in this case: Linq.

Read Blog Post
Refit .NET - my personal caller best practise

Refit .NET - my personal caller best practise

Refit is an open-source library for .NET developers that simplifies the process of making HTTP API calls. It allows developers to define a set of interfaces that describe the API endpoints they want to interact with, and then Refit automatically generates the necessary code to make the HTTP requests. This can significantly reduce boilerplate code and make the interaction with web APIs more type-safe and maintainable.

Read Blog Post
Strong Name Sign .NET Assemblies via SNK

Strong Name Sign .NET Assemblies via SNK

Strong Name Signing is a mechanism in .NET development that ensures the integrity and authenticity of assemblies. It is based on a public-private key procedure.
Contrary to what many assume, this is not a security mechanism, but a mechanism to ensure the uniqueness of the identity. It is therefore also recommended to store both private and public keys directly in the repository - and not to hide them; especially not in open source projects.

Read Blog Post
Handle Yaml Files with .NET

Handle Yaml Files with .NET

YAML files are unfortunately part of everyday life for all developers these days; and although they are very error-prone and almost impossible to edit without an IDE and schema information without constantly running into errors - many greetings to all CI systems that think this was a good idea: it wasn’t - we have to accept that we have to process them.

Read Blog Post
Enable NuGet Audit for better DevSecOps in .NET

Enable NuGet Audit for better DevSecOps in .NET

Auditing is becoming increasingly important in the everyday life of a developer; however, until now there was no particularly good way in .NET - even the lock file still has its deficiencies. You had to rely on third-party packages in order to carry out real auditing of your packages and references or use security software such as WhiteSource or Snyk.

Read Blog Post
Top 5 Git Commit Message Best Practises in 2024

Top 5 Git Commit Message Best Practises in 2024

When you join a project as a new developer, you see one thing above all: no standards for Git commit messages. Some put emojis in the message, others write in the present tense, others in the past tense. But which top 5 rules for Git commit messages have actually become established in the open source community?

Read Blog Post
.NET Naming Best Practises: DTOs

.NET Naming Best Practises: DTOs

Often seen, often used incorrectly: DTOs. Data Transfer Objects.

In principle, DTO is an umbrella term, a design pattern that is used to transfer data between. In reality, however, the umbrella term is used directly as an implementation, which has disadvantages in all cases.

Read Blog Post
The well-structured Entity in EF Core

The well-structured Entity in EF Core

A database entity represents an identifiable entry, often also things from the real world, which are to be stored and managed in the database. The purpose of database entities is to provide a structured and efficient implementation for organizing and managing information. By identifying entities, defining attributes and establishing relationships, a coherent and meaningful structure is created that allows data to be stored, retrieved and updated effectively. This facilitates data management and analysis in applications and systems.

Read Blog Post
When to use optional arguments and parameter defaults in c#

When to use optional arguments and parameter defaults in c#

In C#, optional arguments are parameters in a method that have default values specified in the method’s declaration. This means that when you call the method, you can omit values for these optional parameters, and the method will use the default values defined in its signature. Optional arguments were introduced in C# 4.0 to make it more convenient to work with methods that have a large number of parameters with sensible default values.

Read Blog Post
Re-use EF Core Expressions to avoid redundant queries

Re-use EF Core Expressions to avoid redundant queries

I often see snippets in EF Core code reviews such as the following:

1dbContext.Users.Where( user => user.Id == id );

The query filter user => user.Id == id is contained directly in the Where - often not just in one place but sometimes in dozens of places. Here I ask myself: why is this not simply outsourced to a central place? It’s so simple!

Read Blog Post
Better Code with custom Strong-Id Types

Better Code with custom Strong-Id Types

In many software architectures the problem exists that there are methods, which are specified a multiplicity of type-same parameters, whose meaning is however fundamentally different. In principle, this includes all handling of Ids or other essential values that have a logical meaning.

Read Blog Post
Value Converters in EFCore

Value Converters in EFCore

In the field of software development, data transformation plays a key role in ensuring that information flows seamlessly between different components and systems. When using Entity Framework (EF Core) , a powerful object-relational mapping (ORM) framework, developers can take advantage of value converters to simplify the process of converting data types between applications and databases. . This blog post explains the concept of value converters in EF Core, their benefits, and how to effectively use them in your projects.

Read Blog Post
Simplify string formatting with SmartFormat.NET

Simplify string formatting with SmartFormat.NET

String formatting is a common task in software development and allows you to create dynamic and informative output. Traditional approaches such as string concatenation and compound formatting are widely used, but they quickly become unwieldy and error-prone when formatting requirements become more complex. This is where SmartFormat.NET comes in, a powerful and flexible string formatting library that simplifies the process and offers advanced functionality. In this blog post, we’ll take a look at SmartFormat.NET and how it can improve your string formatting needs.

Read Blog Post
Neuerungen in .NET 8

Neuerungen in .NET 8

Noch ein halbes Jahr bis zum Release von .NET 8 - Zeit sich anzuschauen, was wir neues erwarten dürfen.

LTS Release

.NET 8 ist erneut ein LTS-Release; wie alle geraden Versionsbezeichner. Das bedeutet:

Read Blog Post
Detect Windows 10 and Windows 11 with .NET

Detect Windows 10 and Windows 11 with .NET

Version numbers have always been a rather weird maintained matter under Windows; however, it became particularly bad with Windows 10, respectively 11. Actually, Windows 10 was supposed to be the last version number - but as most people correctly assumed, this has changed as we know.

Read Blog Post
A struct with an interface is inefficient in .NET

A struct with an interface is inefficient in .NET

Structs have their advantages in .NET: they are especially efficient in the runtime if used correctly.

But if you use structs with an interface, the massive advantages unfortunately turn into disadvantages:
As soon as an interface is attached to a struct, Boxing comes into effect; the values are thus copied over and over again, which is usually not what you want - but it also shows up in the benchmarks.

Read Blog Post
Create Symbolic Links on Windows with .NET

Create Symbolic Links on Windows with .NET

Symbolic Links (often abbreviated as symlinks) are a type of file or folder shortcut in Windows that reference another file or folder in the file system, rather than copying its contents. Unlike a normal shortcut, a symlink acts as if it were the original file or folder, so any changes to the symlink will affect the original file, and vice versa.

Read Blog Post
Statische Methoden in C# / .NET

Statische Methoden in C# / .NET

Statische Methoden in C# sind Methoden, die auf eine Klasse und nicht auf eine bestimmte Instanz einer Klasse angewendet werden. Sie können aufgerufen werden, ohne dass zuvor eine Instanz der Klasse erstellt wurde. Ein Beispiel für eine statische Methode ist die Math.Sqrt() Methode, die die Quadratwurzel einer Zahl berechnet.

Read Blog Post
Get Process Id by Name or Path with .NET

Get Process Id by Name or Path with .NET

Getting the process ID by the name or path of a process can be useful for a variety of reasons, such as being able to kill a hanging process or checking if a specific process is running on a machine. In this blog post, I’ll explore how to do this using .NET.

Read Blog Post
Create a Fulltext Catalog with EF Core .NET Migrations for MSSQL

Create a Fulltext Catalog with EF Core .NET Migrations for MSSQL

A full-text catalog in Microsoft SQL Server is a specialized storage that is used to store and manage full-text indexes for one or more tables in a database. A full-text index is a special type of index that is used to support fast, full-text searches of large amounts of text data. It enables users to search for words and phrases within a column of text data in a table, and returns rows that contain the search criteria. Full-text indexes can be created on columns of data that are stored in character data types, such as char, varchar, and text.

Read Blog Post
Compile Linq Expressions to increase performance

Compile Linq Expressions to increase performance

Expressions are now an absolute part of a developer’s everyday life in .NET thanks to Linq.

However, due to their nature, expressions are not one of the very best performing tools, which is why the .NET team is also doing a lot to improve general performance while maintaining usability.

Read Blog Post
DateTime vs. DateTimeOffset - UtcNow vs. Now

DateTime vs. DateTimeOffset - UtcNow vs. Now

.NET has two principal ways for handling times: DateTime and DateTimeOffset .

The big deficit of DateTime, which was also recognized early in .NET 1.0, is that it is not clear from the DateTime information which time zone the time information represents. Therefore DateTime is also called implicit representation of time information, whose “hope” is that the time information is always in relation to UTC-0. DateTime cannot guarantee this, which is why errors often occur in combination with time zones and DateTime. DateTime supports only two possibilities at this point: the local time of the application or UTC.

Read Blog Post
Parse HTML with .NET and the HtmlAgilityPack

Parse HTML with .NET and the HtmlAgilityPack

Parsing HTML with .NET can be a useful skill for any developer working on web applications or data analysis projects. One tool that can be particularly helpful in these scenarios is HtmlAgilityPack , an open-source HTML parser library for .NET. In this blog post, we’ll go over how to use HtmlAgilityPack to parse HTML and extract data from it in a .NET application.

Read Blog Post
Write Json Files asynchronously with .NET

Write Json Files asynchronously with .NET

Writing JSON files asynchronously is a useful technique for improving the performance and scalability of your application. By using an asynchronous approach, you can write JSON data to a file without blocking the main thread, allowing your application to continue running smoothly and respond to user input.

Read Blog Post
Write XML Files asynchronously with .NET

Write XML Files asynchronously with .NET

Writing XML files asynchronously is a useful technique for improving the performance and scalability of your application. By using an asynchronous approach, you can write XML data to a file without blocking the main thread, allowing your application to continue running smoothly and respond to user input.

Read Blog Post
ActivityPub Protocol

ActivityPub Protocol

ActivityPub is an open, decentralized social networking protocol that allows users to share content and interact with each other across the internet. It is based on the concept of the Activity Stream, which is a standard format for representing activities or events that happen on a social networking site.

Read Blog Post
Die .NET UI Technologieübersicht 2022

Die .NET UI Technologieübersicht 2022

Windows Forms aka WinForms

Windows Forms ist eine sehr stark veraltete Technologie, die Aufgrund ihrer Einfachheit jedoch immer noch sehr beliebt ist. WinForms besitzt einen sehr dünnen Layer, der direkt die Win32 API ansteuert, die wiederum GDI+ verwendet.

Read Blog Post
DateTime vs DateTimeOffset - der richtige Umgang mit Zeiten in .NET

DateTime vs DateTimeOffset - der richtige Umgang mit Zeiten in .NET

Dieser Artikel behandelt den korrekten Umgang sowie Best Practises und Empfehlungen von Datums- und Zeitinformationen, Zeitzonen und Betriebssystem-Eigenheiten in Anwendungen, in Text-Dateien, Datenbanken und APIs. Alle Empfehlungen stammen aus dem Open Source-Bereich bzw. stellen eine Zusammenfassung aus der Microsoft Dokumentation dar, zB. .NET: Die Wahl zwischen “DateTime”, “DateTimeOffset”, “TimeSpan” und “TimeZoneInfo”

Read Blog Post
Copy text into the Windows Clipboard with .NET

Copy text into the Windows Clipboard with .NET

To copy text to the clipboard with .NET Framework, usually you have used .NET wrapper of Windows Forms:

1System.Windows.Forms.Clipboard.SetText

However, in the new .NET world, where we want to support many operating systems, this wrapper is rather a hindrance. Thank goodness someone took the trouble and created a very nice, stable library: .NET CopyText on GitHub

Read Blog Post
.NET Updates August 2021

.NET Updates August 2021

Heute hat Microsoft die .NET Updates von August 2021 auf ihrem Blogpost veröffentlicht.

  • Fix CVE-2021-34485: .NET Core Information Disclosure Vulnerability
  • Fix CVE-2021-26423: .NET Core Denial of Service Vulnerability
  • Fix CVE-2021-34532: ASP.NET Core Information Disclosure Vulnerability

Hinweis: in diesen Blog Post hat Microsoft auch erneut .NET Core 2.1 End of life erwähnt!

Read Blog Post
Plugin Mechanism with Parts in ASP.NET Core

Plugin Mechanism with Parts in ASP.NET Core

A plugin-like mechanism is already built into ASP.NET Core, and is called Parts or Application Parts .

In principle, it is a discovery mechanism to be able to use Razor or MVC components such as controllers from other assemblies, for example. Therefore, Application Parts are also particularly well suited for Domain Driven Design (DDD) separation of application components in ASP.NET Core. A DDD abstraction is the most used way of these Application Parts in my applications and architectures.

Read Blog Post
.NET Updates April 2021

.NET Updates April 2021

Heute hat Microsoft die .NET Updates von April 2021 auf ihrem Blogpost veröffentlicht. Diesmal wurden vor allem die Abhängigkeiten wie Docker Images aktualisiert, aber auch ein NuGet Fix bzgl. Zertifikaten ausgeliefert.

Read Blog Post
OpenTelemetry .NET 1.0 veröffentlicht!

OpenTelemetry .NET 1.0 veröffentlicht!

Gestern hat Microsoft die erste stabile Version 1.0 von OpenTelemetry .NET veröffentlicht.

Was ist OpenTelemtry?

OpenTelemetry ist eine Initiative der CNFN (Cloud Native Computing Foundation) und dient dazu, dass Anbieter- und Technologie-übergreifend Informationen von Applikationen zur Verfügung gestellt und ausgewertet werden können.

Read Blog Post
.NET Updates Dezember 2020

.NET Updates Dezember 2020

Gestern hat Microsoft die .NET Updates von Dezember 2020 auf ihrem Blogpost veröffentlicht.

Diesmal gehört dazu maßgeblich das .NET Update 5.0.1, das die ersten kleinen Kinderkrankheiten von .NET 5 beseitigen soll.

Read Blog Post
.NET Updates kommen mit dem Windows Update!

.NET Updates kommen mit dem Windows Update!

Microsoft hat am Donnerstag den zahlreichen Wunsch erfüllt und angekündigt, dass .NET Runtime Updates auf den Windows-Client Versionen ab diesen Dezember mit dem Windows Update ausgeliefert werden und nicht mehr manuell heruntergeladen werden müssen!

Read Blog Post
Enforce english documentations on Microsoft Docs

Enforce english documentations on Microsoft Docs

Microsoft translates the texts of its documentations by machines - and often this unfortunately still ends in total gibberish.

But especially for developer documentations an understandable way of technical expression is very important - which is why many developers from all over the world simply want to read the English documentation instead of a bad local translation.

Read Blog Post
Format DateTime to ISO 8601

Format DateTime to ISO 8601

ISO 8601 is a general, international standard on how the complex representation of time stamps can be formulated in a general way - including the consideration of time formats, time zones and resolution.
Therefore, ISO 8601 is generally recommended for the exchange of time information, whether in databases, XML files or any other potential technology-neutral exchange format.

Read Blog Post
Load an image into a byte-array with C#

Load an image into a byte-array with C#

This pretty simply snippet exports your Image into a byte-array.

1public static byte[] ToByteArray(this System.Drawing.Image image)
2{
3    using(MemoryStream memoryStream = new MemoryStream())
4    {
5        image.Save(memoryStream);
6        return memoryStream.ToArray();
7    }
8}

Usage:

1System.Drawing.Image myImage = .....
2
3byte[] imageAsByteArray = myImage.ToByteArray();

Hint: ImageSharp

ImageSharp uses the same signature to export bytes into a MemoryStream

Read Blog Post
Einfaches WCF-Beispiel ohne komplizierte Config

Einfaches WCF-Beispiel ohne komplizierte Config

Unter anderem durch die Aktivität im myCSharp.de-Forum ist mir aufgefallen, dass viele Entwickler doch Probleme mit der Konfiguration von WCF-Diensten haben. Zugegeben; ich bin auch kein großer Fan des .NET-Konfigurationsframeworks. Es vereinfacht manches, aber es verkompliziert auch vieles, da unnötige Werte Verwirrung stiften.

Read Blog Post