Author Archives: briancaos

About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.

Handling “415 Unsupported Media Type” in .NET Core API

The default content type for .NET Core API’s is application/json. So if the content-type is left out, or another content type is used, you will get a “415 Unsupported Media Type”: This is for example true if you develop an … Continue reading

Posted in .NET Core, c#, General .NET | Tagged , , | Leave a comment

Sitecore AccessResultCache cache is cleared by Sitecore.Caching.Generics.Cache`1+DefaultScavengeStrategy[[Sitecore.Caching.AccessResultCacheKey

Are you getting a lot of these messages in your Sitecore log: 6052 2021:03:25 05:23:12 WARN AccessResultCache cache is cleared by Sitecore.Caching.Generics.Cache`1+DefaultScavengeStrategy[[Sitecore.Caching.AccessResultCacheKey, Sitecore.Kernel, Version=11.1.0.0, Culture=neutral, PublicKeyToken=null]] strategy. Cache running size was xxx MB. This message can easily appear once every … Continue reading

Posted in Sitecore 6, Sitecore 7, Sitecore 8, Sitecore 9 | Tagged , , | Leave a comment

C# Newtonsoft camelCasing the serialized JSON output

JSON love to be camelCased, while the C# Model class hates it. This comes down to coding style, which is – among developers – taken more seriously than politics and religion. But fear not, with Newtonsoft (or is it newtonSoft … Continue reading

Posted in .net, .NET Core, c#, General .NET | Tagged , , , , , | Leave a comment

Simple C# MemoryCache implementation – Understand the SizeLimit property

The .NET Core IMemoryCache is probably the simplest cache there is, and it is very easy to use, once you get your head around the weird SizeLimit property. Especially when using the nice extension methods in this NuGet package: Microsoft.Extensions.Caching.Memory … Continue reading

Posted in .net, .NET Core, c# | Tagged , , | Leave a comment

C# get results from Task.WhenAll

The C# method Task.WhenAll can run a bunch of async methods in parallel and returns when every one finished. But how do you collect the return values? Imagine that you have this pseudo-async-method: And you wish to call that method … Continue reading

Posted in General .NET | Leave a comment

C# .NET Core Solr Search – Read from a Solr index

.NET Core has excellent support for doing searches in the Solr search engine. The search language is not always logical, but the search itself is manageable. Here’s a quick tutorial on how to get started. STEP 1: THE NUGET PACKAGES … Continue reading

Posted in General .NET | Leave a comment

Write to file from multiple threads async with C# and .NET Core

There are several patterns on how to allow multiple threads to write to the same file. the ReaderWriterLock class is invented for this purpose. Another classic is using semaphors and the lock statement to lock a shared resource. This article … Continue reading

Posted in .net, .NET Core, c#, General .NET | Tagged , , , , | Leave a comment

HttpClient retry on HTTP timeout with Polly and IHttpClientBuilder

The Polly retry library and the IHttpClientBuilder is a match made in heaven as it defines all the retry logic at startup. The actual HttpClient  calls are therefore untouched by any retry code. The retry logic is called policies, and … Continue reading

Posted in .net, .NET Core, c# | Tagged , , , | 2 Comments

Azure Cognitive Search from .NET Core and C#

The Azure Cognitive Search engine is the search of choice in the Microsoft Azure. The search engine can be used in a myriad of ways and there are so many options that it can be difficult to find a starting … Continue reading

Posted in .NET Core, c#, General .NET, Microsoft Azure | Tagged , , , | Leave a comment

Programmatically create and delete Azure Cognitive Search Indexes from C# code

Azure Cognitive Search is the search engine of choice when using Microsoft Azure. It comes with the same search features as search engines like Elastic Search and SOLR Search (you can even use the SOLR search query language). One cool … Continue reading

Posted in General .NET | 1 Comment