Category Archives: c#

Add a UserAgent to the IHttpClientFactory in .NET Core

Using a IHttpClientFactory to create HttpClient connections have a number of advantages, as you can configure several httpclients on startup. Each client will be reused, including the properties attached to that client. In a previous post I showed how to … Continue reading

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

Sending JSON with .NET Core QueueClient.SendMessageAsync

You need to Base64 encode JSON serialized strings before adding them to a queue Continue reading

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

Sitecore Publish item when moved or dragged using uiMoveItems and uiDragItemTo pipelines

Sometimes you have items that needs to be published immediately if moved to a new location in the content tree. Sitecore supports this – of course – via the uiMoveItems and uiDragItemTo pipelines. This technique really applies to whatever you … Continue reading

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

Run tasks in parallel using .NET Core, C# and async coding

If you have several tasks that can be run in parallel, but still need to wait for all the tasks to end, you can easily achieve this using the Task.WhenAll() method in .NET Core. Imagine you have this imaginary method … Continue reading

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

Method not found: ‘Void Sitecore.ContentSearch.Diagnostics.AbstractLog.SingleWarn(System.String, System.Exception)’.

I struggled with this error in my development environment: Method not found: ‘Void Sitecore.ContentSearch.Diagnostics.AbstractLog.SingleWarn(System.String, System.Exception)’. at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, … Continue reading

Posted in .net, c#, Sitecore 8, Sitecore 9 | Tagged , , | Leave a comment

C# Set local folder for .net Core Windows Services

When developing .NET Core Worker Services, you can allow the service to run as Windows Service: The side effect is that the root folder changes from the local folder to the System32 folder, which means that any log files that … Continue reading

Posted in .NET Core, c# | Tagged , , | 1 Comment

Manipulating XML Google Merchant Data using C# and LINQ

Receiving a Google Merchant Data feed (also known as a Google Product Feed) can be fairly easily manipulated on import time using a little C# and LINQ. The feed is basically a XML RSS 2.0 feed with some added properties … Continue reading

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

C# Azure TelemetryClient will leak memory if not implemented as a singleton

I noticed that my classic .net web application would leak memory after I implemented metrics for some background tasks. Further investigation showed that my MetricAggregationManager would not release its memory. Since one of the major changes was the implementation of … Continue reading

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

Remove duplicates from XML feed

Apparently XML isn’t dead yet, and today I received a Google Product Feed in the RSS 2.0 XML format. The feed was full of duplicates and my job is to remove them: As you can see, “Product 100” appears twice. … Continue reading

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

.NET Core Worker Services with Application Insights and Serilog

The .NET Core Worker service is yet another tool in the .NET toolbox. They are perfect for background processing like reading from a queue or making health checks. They are cross-platform (of course) and they can run on docker containers, … Continue reading

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