Get Users from IdentityServer using .NET Core
If you wish to poke around in the IdentityServer users database directly, the API seems a little bit fishy. This is because the direct data access are very low level, and consists of HttpClient...
View ArticleC# Log to Application Insights and File from your .NET 6 Application
So why would you ever log to Application Insights AND File log at the same time? Well, if you are hosting your own applications on your own machine, it can be great to have a file version of what’s...
View ArticleC# Thread Safe File Writer and Reader
Previously I wrote the article Write to file from multiple threads async with C# and .NET Core, which explains how to use a ConcurrentQueue to append lines to a text file. And the ConcurrentQueue is...
View ArticleCreate C# Class from SQL
I hate doing plumbing code. Especially entity model classes that are exact replicas of SQL tables. I do this all the time when using Dapper. So I did some googling and found some SQL statements that...
View ArticleC# List Batch – Braking an IEnumerable into batches with .NET
There are several ways of batching lists and enumerables with C#. Here are 3 ways: METHOD 1: USING MoreLINQ MoreLINQ is an extension package for LINQ that implements yet another set of useful LINQ...
View ArticleC# Ignoring Namespaces in XML when Deserializing
Namespaces in XML are hard to understand, I’ll admit that. But even I have learned that namespaces in XML documents matter. These elements are not the same: <item> <title>Brian...
View ArticleC# Convert WebP to JPEG in .NET
WebP is a new compressed image format developed by Google. If you want to convert WebP to any other format, you seem to be mostly out of luck if you are using C#. There is, however, some tools out...
View ArticleC# SQL Connection Using Azure Managed Identity
Azure Managed Identity is Microsoft’s solution to manage credentials for you, eliminating the need to store usernames, passwords, certificates and other secrets in your config files. Basically, with...
View ArticleSitecore Create Fully Qualified Url
A classic issue in Sitecore: Some code running in one Site Context is creating a link to a page in another context, and the link turns out to be complete garbage. For example, this code is running in...
View ArticleBuild .net core 6 projects with Azure Devops using yml files
DevOps is a complicated discipline, so when you as a developer have to set up a build pipeline in Azure Devops you are sometimes in deep water. Thats why I made this yml template that I can copy from...
View Article.NET API CORS: Response to preflight request doesn’t pass access control...
What to do if you get the following error in the browser when calling a CORS protected .NET Core API endpoint: Response to preflight request doesn't pass access control check: No...
View ArticleC# .net Swagger API Versioning – Show versions in your Swagger page
So, Swagger does in fact support versioning in the interface. You just need to do it right, and remember to apply all the attributes and methods. An API with 2 versions, version 7 and version 8 First...
View ArticleSerialization and deserialization of ‘System.IntPtr’ instances are not...
I added exception handling to my .net core 6 API, and any of my error messages just throws an error 500. The complete exception is as follows: System.NotSupportedException: Serialization and...
View ArticleC# Azure Table Storage QueryAsync, Paging and Filtering
Azure Table Storage is a NoSQL key-value store that can store massive amounts of data in a semi-structured way. Data is stored using a PartitionKey/RowKey keyset and a list of values. So far so good,...
View ArticleRun node.js on Windows server using NSSM
Node.js was probably never intended to be run on a windows server. It runs perfectly on Linux, and you can also run it without problems as an Azure App Service. But what if Node.js has to run on a...
View ArticleSitecore SOLR Search in multiselect lists fails unless you add the field to...
So I have this multiselect field in Sitecore: Sitecore Treelist Field The field is a treelist field, but this article works for all multiselect fields, treelist, checklist, multilist, etc. Treelist...
View ArticleC# Authorization in .NET Core API’s using Attributes, TypeFilterAttribute and...
So the goal here is to define that a specific API endpoint in my .NET Core API requires an authorization token. It’s not all my endpoints that requires authentication, only those I specify. To obtain...
View ArticleCould not load file or assembly ‘System.Diagnostics.DiagnosticSource,...
The following error may occur when upgrading Microsoft ApplicationInsights: [FileNotFoundException: Could not load file or assembly ‘System.Diagnostics.DiagnosticSource, Version=4.0.4.0,...
View ArticleSitecore TargetInvocationException: Exception has been thrown by the target...
You are probably upgrading some packages in your Sitecore instance, but instead of success and glory, you are greeted with the following error message: [TargetInvocationException: Exception has been...
View ArticleParameters and Arguments in .NET Core Command Line Applications
Microsoft have released a new System.CommandLine library to handle parameters and arguments in your .NET Core 6 console applications. The NuGet Package is currently (March 2nd 2023) in beta, so you...
View Article