Skip to main content


Showing posts from July, 2021

AD FS Help

ADFS is great as long as it works. But when you get into trouble, all the help you can find is welcome… While investigating an ADFS issue, I found the AD FS Help website : This website combines a list of of both online and offline tools that can help you configure, customize and troubleshoot your ADFS instance.

GraphQL HotChocolate 11 - Updated Application Insights monitoring

A few months ago, I blogged about integrating Application Insights in HotChocolate to monitor the executed GraphQL queries and mutations. In HotChocolate 11, the diagnostics system has been rewritten and the code I shared in that post no longer works.  Here is finally the updated post I promised on how to achieve this in HotChocolate 11. Creating our own DiagnosticEventListener Starting from HotChocolate 11, your diagnostic class should inherit from DiagnosticEventListener. We still inject the Application Insights TelemetryClient in the constructor: Remark: There seems to be a problem with dependency injection in HotChocolate 11. This problem was fixed in HotChocolate 12. I show you a workaround at the end of this article. In this class you need to override at least the ExecuteRequest method: To track the full lifetime of a request, we need to implement a class that implements the IActivityScope interface. In the constructor of this class, we put all our initi

dotnet monitor–Run as a sidecar in a Kubernetes cluster–Part 2

Last week I blogged about how you can run dotnet monitor as a sidecar in your Kubernetes cluster . Although the yaml file I shared worked on my local cluster (inside Minikube), it didn’t work when I tried to deploy it to AKS. Nothing happened when I tried to connect to the specified URL’s. To fix this I had to take multiple steps: First I had to explicitly set the ‘—urls’ argument inside the manifest: Now I was able to connect to the url but it still failed. When I took a look at the logs I noticed the following message: {"Timestamp":"2021-07-27T18:48:29.6522095Z","EventId":7,"LogLevel":"Information","Category":"Microsoft.Diagnostics.Tools.Monitor.ApiKeyAuthenticationHandler","Message":"MonitorApiKey was not authenticated. Failure message: API key authentication not configured.","State":{"Message":"MonitorApiKey was not authenticated. Failure message: A

NDepend–DDD Rule

A few weeks ago I was contacted by Patrick Smacchia , the creator of NDepend , if I would check out the latest edition of their code quality tool. As I had an upcoming software audit assignment planned, I thought it would be a great occasion to see what NDepend brings to the table and how it can help me to improve my understanding of an unfamiliar codebase. NDepend offers a lot of rules that are evaluated against your code. These rules can help you identify all kind of issues in your code. If you want to learn more about this feature check out the following video:   All these rules are created using CQLinq(the code query language of NDepend) and can be customized to your needs (and the specificalities of your project). One rule that got my interest was the ‘ DDD -  ubiquitous language check ’. This rule allows you to check if the correct domain language terms are used. It is disabled by default(because it should be updated to reflect your domain language). Let’s see how to up

AKS–Limit ranges

Last week, we got into problems when booting up our AKS cluster(we’ll shut the development cluster down every night to safe costs). Instead of green lights, our Neo4J database refused to run. In the logs, we noticed the following error message: ERROR Invalid memory configuration - exceeds physical memory. Let me share what caused this error. Maybe you’ve read my article about resource limits in Kubernetes . There I talked about the fact that you can set resource limits at the container level. What I didn’t mention in the article is that you can also configure default limits at the namespace level through limit ranges . From the documentation : A LimitRange provides constraints that can: Enforce minimum and maximum compute resources usage per Pod or Container in a namespace. Enforce minimum and maximum storage request per PersistentVolumeClaim in a namespace. Enforce a ratio between request and limit for a resource in a namespace. Set defaul

Azure Kubernetes Service- Failed to acquire a token

When invoking ‘kubectl’, it failed with the following error message: PS /home/bart> kubectl apply -f ./example.yaml E0720 07:58:14.668222     182 azure.go:154] Failed to acquire a token: unexpected error when refreshing token: refreshing token: adal: Refresh request failed. Status Code = '400'. Response body: {"error":"invalid_grant","error_description":"AADSTS700082: The refresh token has expired due to inactivity. The token was issued on 2021-03-31T13:22:18.9100852Z and was inactive for 90.00:00:00.\r\nTrace ID: 68f8e37d-4d18-4e7d-a3e6-b11291831a02\r\nCorrelation ID: 65ee9420-d6f9-4a7c-8214-a82756c7ecc8\r\nTimestamp: 2021-07-20 07:58:14Z","error_codes":[700082],"timestamp":"2021-07-20 07:58:14Z","trace_id":"68f8e37d-4d18-4e7d-a3e6-b11291831a02","correlation_id":"65ee9420-d6f9-4a7c-8214-a82756c7ecc8","error_uri":" https://login.microsoftonlin

Passing a cancellation token to an IAsyncEnumerable

I talked about the concept of asynchronous streams before. Thanks to the introduction of the IAsyncEnumerable interface, it allowed us to combine the richness of LINQ with the readibility of async-await to asynchronously access databases, microservices and remote APIs. As enumerating async streams will typically result in remote asynchronous operations it can take a while to complete. I was wondering how we could cancel these async operations? To support this use case, IAsyncEnumerable has an extension method ‘ WithCancellation() ’. The CancellationToken will be passed on to the  IAsyncEnumerable.GetEnumerator method. More information about what’s happening behind the scenes can be found here . Remark: There are some further improvements on the way in ASP.NET Core 6 regarding consuming IAsyncEnumerable streams as mentioned in this post: .

Kubernetes–What is the difference between resource requests and limits?

In Kubernetes it is a best practice to configure resource limits for your containers. VSCode will even warn you if it couldn’t detect resource limits in your manifest files: Setting resource limits prevents a container consuming too much resources and impacting other workloads. By setting limits, pods will be terminated by Kubernetes when their limits are exceeded. This helps in keeping the cluster healthy and stable. The most common resources to specify are CPU and memory, but others exists. Here is a short example on how to configure this at the container level: In the example above, the CPU usage is limited to 250m or  250 milliCPU (1/4th of a vCPU/Core) and memory usage is limited to 512Mi or 512MiB. Next to resource limits, it is also possible to configure resource requests . Setting a resource request indicates the amount of that resource that you expect the container will use. Kubernetes will use this information when determining which node to schedule the pod on.

Windows Terminal–Add Git Bash

I’ve started to love Windows Terminal . So it would be nice if I could add Git Bash to the list of possible terminal experiences. Before you can start integrating Git Bash,make sure that it is available on your system. You can install it as part of the Git for Windows experience. Open up Windows Terminal and select the down arrow in the tab bar at the top. Select Settings from the dropdown menu. This opens the Settings tab for Windows Terminal. I first tried to add a new Profile for Git Bash using the Add new option on the left but I couldn’t get it working. What I did instead was choosing the Open JSON file option. Now I could directly alter the configuration file. In the profiles list I added the following configuration:

.NET Conf–Focus on F#

Great news for all F# developers, a new .NET Conf is coming up at the end of July with only one topic on the agenda; F# ! .NET Conf: Focus on F# is a free, one-day livestream event that features speakers from the community and Microsoft teams working on and using the F# language. Learn how F# lets you write succinct, performant, and robust code backed by a powerful type system and the .NET runtime you can trust to build mission-critical software. Hear from language designers and experts using F# in a variety of ways from building minimal web APIs to performing data manipulation, interactive programming, machine learning, and data science. Tune in here on July 29, ask questions live, and learn about what F# can do.  

Front-End Performance Checklist 2021

For everyone who cares about the performance of their web applications (don’t we all?) this is really, really a must read. It took me 2 days to go through all the material, links and related articles but boy was it worth it! I hope that the teams I work with are ready because I will have a long list of questions and remarks coming up! Let’s make 2021… fast! An annual front-end performance checklist (available as PDF , Apple Pages , MS Word ), with everything you need to know to create fast experiences on the web today, from metrics to tooling and front-end techniques.

NDepend–Find out where a library is used–Part 2

A few weeks ago I was contacted by Patrick Smacchia , the creator of NDepend , if I would check out the latest edition of their code quality tool. As I had an upcoming software audit assignment planned, I thought it would be a great occasion to see what NDepend brings to the table and how it can help me to improve my understanding of an unfamiliar codebase. Yesterday I shared how I was able to generate the CQLinq query I needed through the class browser. While writing that post I noticed that NDepend also suggested me to use another feature to get there. When creating a new query, the editor suggests you to have a look at the code search feature: So let’s do that today. I opened Search (View –> Search View). Let’s see if we can find all Repository objects. I change the ‘Element’ value to ‘Type’ and enter ‘Repository’ in the search field. NDepend picks this up and generates a CQLinq query for me.

NDepend–Find out where a library is used directly and indirectly

A few weeks ago I was contacted by Patrick Smacchia , the creator of NDepend , if I would check out the latest edition of their code quality tool. As I had an upcoming software audit assignment planned, I thought it would be a great occasion to see what NDepend brings to the table and how it can help me to improve my understanding of an unfamiliar codebase. In preparation of the software audit, the software architect told me that one of the problems of their current codebase is that their data access logic was spread out everywhere throughout the code. They already started an effort in isolating the data access logic but he had no clue how far this has progressed. Let’s see if we can find the answer using NDepend. I had read in the documentation that NDepend offers the ability to query the code model using CQLinq. As a developer I like to code, so let’s try that first… I opened VisualNdepend, loaded the NDepend project I wanted to investigate and hit CTLR-R (or go through View

ASP.NET Core–Generate URL using Url.Action

I needed to generate a URL that I could return inside an ASP.NET Controller. Thanks to the built-in UrlHelper that is something that even I can do. At least that was what I thought… This is the code I tried: Surprisingly this didn’t work.  It turns out that the controller argument needs the controllername without the controller suffix.  So in my example above ProductController should be Product instead. I changed it to this: Still refactor friendly but unfortunately a lot less readible.

NDepend–Don’t extract it in your Program Files!

A few weeks ago I was contacted by Patrick Smacchia , the creator of NDepend , if I would check out the latest edition of their code quality tool. As I had an upcoming software audit assignment planned, I thought it would be a great occasion to see what NDepend brings to the table and how it can help me to improve my understanding of an unfamiliar codebase. After a reply to Patrick I got a link to the Professional edition but you can download a trial version here . NDepend doesn’t have an installer but is provided as a zip file. I extracted it to my %Program Files% folder and had a look at what was in there: VisualNDepend.exe looked promising so I double clicked on that executable. Unfortunately nothing happened !? Hmmm, maybe I should not be so eager and first read the README.txt file available in the zip? OK, the first 2 lines in the README immediatelly point out my mistake; This file contains information about NDepend files when unzipped. Don't unzip th

dotnet monitor–Run as a sidecar in a Kubernetes cluster

Yesterday I blogged about ‘dotnet monitor’ and how it can help you to collect diagnostic artifacts at runtime in a uniform way. Let’s have a look today on how to use ‘dotnet monitor’ inside a Kubernetes cluster. When running in a cluster, it is recommend to run the dotnet-monitor container as a sidecar alongside your application container in the same pod. Here is an example manifest on how to set this up: Most important to notice in the manifest is that you need to share a volume between the application container and the sidecar. Let’s deploy this manifest: $ kubectl apply –f ./dotnetmonitor.yaml Once your pods are up and running, we need to use port forwarding to be able to access the diagnostics endpoint from our local machine. To do this, we first need to find the name of the pod : $ kubectl get pod -l app=dotnet-monitor-example NAME READY STATUS RESTARTS AGE dotnet-monitor-example-78997f8fdf-nrhp7 2/2 Running 0

dotnet monitor - Getting started

With the announcement that ‘dotnet monitor’ graduated to a supported tool in .NET ecosystem, I putted it on my list of tools to have a look at. Now the summer vacation has started I finally found some time to try it out. What is ‘dotnet monitor’? Before I dive in on how to start using dotnet monitor, let’s explain what it does: Dotnet monitor aims to simplify collecting diagnostics artifacts (e.g. logs, traces, process dumps) by exposing a consistent REST API regardless of where your application is run. This makes your application easy debuggable no matter if it is running locally, in a docker container, or in Kubernetes. So dotnet monitor gives you an uniform and easy accessible way to check what is going on inside your dotnet core application. Getting started We’ll have a look at how we can use dotnet monitor in a sidecar container in another post, let us now focus on using it as a local tool. Dotnet monitor is distributed as a .NET Core global tool and can be installe

Using the correct HTTP Status codes when building REST api’s

One of the important elements in building a good REST api, is the correct usage of the HTTP Status Codes . A help in identifying the correct status code to return is the following ’http decision diagram’ . This diagram describes the resolution of HTTP response status codes, given various headers. It follows the indications in RFC7230 RFC7231 RFC7232 RFC7233 RFC7234 RFC7235 , and fills in the void where necessary. You can find this diagram here:

ASP.NET Core–Read data from the HttpClient in a memory efficient way

I created a service that allowed users to download all address data from Belgium in CSV format. By default when fetching this data through the HttpClient it would result in having the full blob into memory. But thanks to the power if IAsyncEnumerable<> and setting the HttpCompletionOption.ResponseHeadersRead flag when calling GetAsync() I could get this done in a very efficient way: By setting the HttpCompletionOption.ResponseHeadersRead flag the client would only wait until the headers are received and then continue execution. So I could start processing the results before all data was downloaded.

Understanding the GraphQL specification

If you are really interested in GraphQL, reading through the spec is certainly a good idea. Although really well written, it can still be not that fun to go through. As an alternative you could have a look at the blog series written by Loren Sands-Ramshaw in which he walks you through the most important parts of the specification in a more digestable way: Part 1: Query language Part 2: Type system Part 3: Validation & execution  

ASP.NET Core: CreatedAtAction - No route matches the supplied values

After creating a new item I wanted to return the location where the newly created item could be fetched. So I used the CreatedAtActionResult to specify the action. Here is the code I was using: And here is the related GetById method: I wouldn’t be writing this blog post if everything worked as expected. When calling the CreateAsync method, I got the following error message: No route matches the supplied values . I couldn’t figure out what I was doing wrong until I took a look at the different overloads of CreatedAtAction: If you look at the code above, you notice that I’m using the second overload. This overload expects 2 parameters: actionname : The name of the action to use for generating the URL value : The content value to format in the entity body I was passing a‘new { id = product.Id } ’value expecting that it would be matched to the ‘id’ parameter that the route was expecting. This turned out not to be the case as the second overload uses the passed