C# Dapper Trim String Values
I was calling a stored procedure using Dapper, and for reasons beyond my understanding, the stored procedure returned strings as non-trimmed strings: Strings are not trimmed when returned from my...
View ArticleC# byte size to string
How do you convert a byte size into a human readable string? There are many many ways of doing this. I made probably the simplest and most readable version, and wrapped it as an extension method:...
View ArticleSitecore The type or namespace name ‘Job’ does not exist in the namespace...
From Sitecore 9.0 to Sitecore 9.2, Sitecore updated the Jobs namespace: Job have become Sitecore.Abstractions.BaseJob abstract class and Sitecore.Jobs.DefaultJob concrete implementation. JobOptions...
View ArticleC# String Token Replacer
Imagine this classic text where you need to replace tokens with some values: Welcome {{user}}. Click on this link to confirm your subscription: {{url}}. Tokens encapsulated in double brackets...
View ArticleC# HttpClient and IHttpClientFactory in .net core
The C# HttpClient is the go-to library when you need to GET, PUT, POST or DELETE from an API Endpoint. But one of the issues with HttpClient is that it needs to be instantiated as a singleton. This is...
View ArticleC# Use HttpClient to GET JSON from API endpoint
So, most API endpoints return JSON anyway, right? So why not make a method that can make a GET call to an API and return the response as an object directly? It’s actually not that hard: STEP 1: MAKE A...
View Article.NET Core Caching in your API using AddResponseCaching and ResponseCache...
Caching the response of an API speeds up the API endpoint because the code that generates the response is not called, but rather fetched from memory. This is especially helpful for API’s where the...
View ArticleC# Calculate Week Number from DateTime
Calculating the week number is harder than it should be. Not all countries calculate week numbers equally. First you need to know when a week starts. On a sunday? or on a monday? Then you need to know...
View ArticleC# JWT Token Get Expiry Timestamp
In a previous post, I wrote on how to use JWT.Net to decode the JWT Token to get the expiry of the token. But there is a simpler way to do it. IdentityServer, among others, use this token to establish...
View ArticleC# Convert XML to JSON using dynamic ExpandoObject, XDocument and...
So I receive these XML feeds from my client, but I need to enrich the contents before I can use the data. AND I would like to work with JSON instead. So how to do that with a few lines of code? Image...
View ArticleSitecore Scheduled Tasks Run only when you want them to
Sitecore Scheduled Tasks is one of the fundamental features of Sitecore that allows you to run background tasks based on a schedule. The most common scheduled task runner is the one that looks for...
View ArticleNesting appsettings.config files in Visual Studio
So I added .config files for my development, preproduction and production environment, but Visual Studio just added the files at the same level as the appsettings.config file: Visual Studio showing...
View ArticleError CS0121: The call is ambiguous between the following methods or...
So I wanted to add a ITelemetryProcessor to my project. I created a DependencyTelemetryFilter and applied the filter as I always do: services...
View ArticleC# ‘SHA256Managed’ is obsolete: ‘Derived cryptographic types are obsolete....
So my code gives me this warning: Warning SYSLIB0021 ‘SHA256Managed’ is obsolete: ‘Derived cryptographic types are obsolete. Use the Create method on the base type instead.’ The code that warns me...
View ArticleC# Application Insights Errors are Logged as Traces – How do I log them as...
So when I log to Application Insights, I first follow this guide to set up Application Insights AND File logging: C# Log to Application Insights and File from your .NET 6 Application To create a log...
View ArticleSitecore: Unable to load the service index for source...
Here is what you do if you receive messages like this: Errors in packages.config projectsUnable to find version ‘9.0.171219’ of package...
View ArticleSitecore: Insert Link tree does not expand
In my development Sitecore, I had this strange situation that when I tried to insert a link, the tree would not fold out for certain items: The content tree does not expand in the “insert link” dialog...
View ArticleC# Dapper convert numbers to 2 decimals
I had this problem when inserting numbers into a SQL database using Dapper. All of my numbers did not round correctly when being inserted, even when using Math.Round() before doing the insert. My...
View ArticleC# Dapper Async Bulk Inserts
In order for Dapper to do bulk inserts, you need a third-party library: Z.Dapper.Plus Once you have this package, bulk inserts are at your fingertips. Async is supported in a rather special way. Lets...
View ArticleC# Inject ILogger into Dapper Polly Retry Policy
There are many articles describing how to make a retry policy when using Dapper. I especially like this extension method implementation. But you cannot inject any class into extension methods because...
View Article