Legal Notice
The opinions expressed herein are my own personal opinions and do not represent my employer’s view in anyway.Top Posts
- C# DateTime to UNIX timestamps
- C# HttpClient POST or PUT Json with content type application/json
- C# get results from Task.WhenAll
- Write to file from multiple threads async with C# and .NET Core
- Run tasks in parallel using .NET Core, C# and async coding
- Build .net core 6 projects with Azure Devops using yml files
- .NET API CORS: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header.NET API
Archive
Meta
Category Archives: c#
.NET Core Caching in your API using AddResponseCaching and ResponseCache attribute
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 response is time-consuming to retrieve but … Continue reading
Posted in General .NET, .net, c#, .NET Core
Tagged .NET, API, Cache, Querystring, ResponseCache, VaryByHeader, VaryByQueryKeys
Leave a comment
C# 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 … Continue reading
Posted in .net, .NET Core, c#, General .NET
Tagged Asynchronous, generics, Http, HttpClient, IHttpClientFactory, JSON
Leave a comment
C# 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 a … Continue reading
Posted in .net, .NET Core, c#, General .NET
Tagged Asynchronous, Await, HttpClient, IHttpClientFactory, Static
1 Comment
C# 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 {{token}} are commonly used to mark tokens to be replaced with … Continue reading
Posted in .net, c#, General .NET
Tagged Email, Extension Methods, SparkPost, String, Token
Leave a comment
Sitecore The type or namespace name ‘Job’ does not exist in the namespace ‘Sitecore.Jobs’ (are you missing an assembly reference?)
From Sitecore 9.0 to Sitecore 9.2, Sitecore updated the Jobs namespace: This resonates with the Sitecore structural changes where Sitecore implements abstractions for most of their code. This change began all the way back in Sitecore 7.5 and makes it … Continue reading
Posted in c#, Sitecore 10, Sitecore 9
Tagged Abstractions, DefaultJob, Jobs, Sitecore
Leave a comment
C# 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: Please note that this … Continue reading
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: I could of course look into the stored procedure, but that would require me to obtain new knowledge … Continue reading
Posted in .net, .NET Core, c#, General .NET
Tagged Dapper, Database, SQL, TypeHandler
Leave a comment
Parameters 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 need to allow prerelease NuGet packages in your solution. … Continue reading
Posted in .net, .NET Core, c#, General .NET
Tagged .NET 6.0, Argument, Command Line, Help, Parameter
1 Comment
Could not load file or assembly ‘System.Diagnostics.DiagnosticSource, Version=4.0.4.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’ or one of its dependencies. The system cannot find the file specified
The following error may occur when upgrading Microsoft ApplicationInsights: [FileNotFoundException: Could not load file or assembly ‘System.Diagnostics.DiagnosticSource, Version=4.0.4.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’ or one of its dependencies. The system cannot find the file specified.]Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule.Application_BeginRequest(Object sender, EventArgs e) +0System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +142System.Web.<>c__DisplayClass285_0.b__0() +38System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +11857717System.Web.HttpApplication.ExecuteStep(IExecutionStep … Continue reading
Posted in c#, General .NET, Sitecore 10, Sitecore 7, Sitecore 8, Sitecore 9
Tagged Application Insights, Binding, Dependency, NuGet
Leave a comment
C# Authorization in .NET Core API’s using Attributes, TypeFilterAttribute and IAuthorizationFilter
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 this, I would like to … Continue reading
Posted in .net, .NET Core, c#, General .NET
Tagged API, Authorization, IAuthorizationFilter, TypeFilterAttribute
Leave a comment