Quantcast
Channel: Brian Pedersen's Sitecore and .NET Blog
Browsing all 285 articles
Browse latest View live

Image may be NSFW.
Clik here to view.

Nesting 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 Article


Error 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 Article


C# ‘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 Article

Image may be NSFW.
Clik here to view.

C# 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 Article

Sitecore: 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 Article


Image may be NSFW.
Clik here to view.

Sitecore: 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 Article

Image may be NSFW.
Clik here to view.

C# 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 Article

C# 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 Article


C# 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


C# Convert array of objects into a DataTable

This extension method lets you convert an array of objects into a DataTable. DataTables are used for SQL inserts. This solution is not mine, in fact it has been copied so many times that I don’t know...

View Article

C# SqlBulkCopy insert a list of objects

The SqlBulkCopy class is able to bulk insert data from anything that comes from a DataTable or can be read using a SqlDataReader. So what do you do if you have an array of objects? You have to convert...

View Article

C# Connect to 2 or more databases using a Datacontext

This is more of a design pattern than it is a requirement. I use this technique when my application grows in size. When my application needs to connect to 2 or more databases, I use this encapsulation...

View Article

Image may be NSFW.
Clik here to view.

C# Game Of Life

The Game Of Life is a cell life simulator devised by the Cambridge mathematician John Conway. Game Of Life in a Console Application The simulator serves as an excellent coding example to learn new...

View Article


Image may be NSFW.
Clik here to view.

C# Marking Deprecated Code As Obsolete

If a certain piece of code is no longer relevant or needed, or if it’s no longer maintained, you can mark it as obsolete. Use the [Obsolete] tag to mark the code. You can mark a function:...

View Article

Image may be NSFW.
Clik here to view.

C# Add UserAgent to Application Insights Request Telemetry using a Middleware

This is probable rather specific, but I have this API endpoint, and in my Application Insights I need the UserAgent whenever I log a Request. Custom Properties of a Request Telemetry in Application...

View Article


C# Sort List of Dynamic Objects

The dynamic type in C# is a static type that bypasses static type checking. This makes it possible for you to work with objects like they were strongly typed, but without having to create named model...

View Article

C# Sort JArray NewtonSoft.Json

OK, just to burst your bubble: You cannot sort JArray. But if your JArray is just a list of numbers, or letters, you can convert the JArray into a list, sort that, and put it back into your JArray. In...

View Article


C# Lowercase all JSON attributes in your API responses

When creating an API in C#, you can control how your JSON response should be formatted. The classic way is to us the JsonPropertyName attribute and define the output in a per-field manner: using...

View Article

Azure Functions: No job functions found. Try making your job classes and...

This error message might occur when working with Azure Functions in Isolated Mode: No job functions found. Try making your job classes and methods public. If you’re using binding extensions (e.g....

View Article

Convert JSON Arrays into batches of JSON Arrays using the LINQ Chunk method

This is one way of converting a JSON array of any JSON objects into batches. This function uses the LINQ Chunk method to convert a 1 dimensional array input into a 2 dimensional array output: Example...

View Article
Browsing all 285 articles
Browse latest View live