Skip to main content

Posts

Showing posts from January, 2023

Switch between node versions on Windows

By default, you have 1 node.js and NPM version installed on your machine. However, if you have to maintain applications written in multiple Angular and/or Typescript versions, this can become a problem. Older Angular/Typescript applications are not compatible with the latest node.js version and can no longer be compiled. In Linux, this has been solved by the introduction of nvm , the node version manager. With it, it is possible to quickly install(and uninstall) different node.js versions and easily switch between them via the command line. NVM-Windows With nvm-windows , an alternative is also available for Windows. You can easily install nvm-windows on your local machine via the installer available here: https://github.com/coreybutler/nvm-windows/releases . Using nvm-windows is very simple: Install a node.js version: nvm install <version> Listing the installed versions: nvm list Switching between versions: nvm use <version> No...

Central Package Management - warning NU1507: There are 2 package sources defined in your configuration.

A few weeks ago, I talked about a new NuGet feature, Central Package Management . This allows you to manage your dependencies at the solution level instead of at the project level. After converting one of my projects to use Central Package Management, I noticed the following warning in Visual Studio: warning NU1507: There are 2 package sources defined in your configuration. When using central package management, please map your package sources with package source mapping ( https://aka.ms/nuget-package-source-mapping ) or specify a single package source. The following sources are defined: nuget.org, company.be. I get this warning because I have 2 package sources defined, one at the machine level and one at the solution level in my nuget.config. I could get rid of this warning by using a single package source.Therefore I need to update my nuget.config file to have only 1 package source defined and add a <clear /> statement to not use package sources found at other level...

There is no such thing as a requirement

In software development we are used to the term ‘ requirement '. I don't like this term and I will explain why. Using the word requirement puts a strong emphasis on 'required'; 'this is something that is required' or it is 'something the business MUST have to succeed' . But by describing it as required, there is no room for discussion. Is this really what the business needs? Does it make sense? Or is there maybe a better solution?  What if we can achieve the same outcome in a different way? If it really was required, the business would not exist or even function. So by definition what the business asks for cannot be a requirement, a necessity. There is no such thing as a requirement When I hear the word requirement, I always have to think about the following quote: “If I had asked people what they wanted, they would have said faster horses.” Although there is no evidence that Henry Ford ever said those words, I believe he was certainly thi...

Cleanup old MetricBeats data

At one of my clients we are using MetricBeats to monitor our RabbitMQ cluster . Of course this can result in a lot of data over time. Recently I was called by one of the system administrators asking why the disk was filling up on the servers hosting ElasticSearch. Let’s find out together… Index lifecycle policies To keep the amount of data on your ElasticSearch cluster under control, you can configure a lifecycle policy . A lifecycle policy moves data through multiple phases; A hot phase: used for your most recent most frequently searched data. It provides the highest indexing AND search performance but comes with the highest cost A warm phase: optimized for search performance over index performance. In this phase it is expected that the data doesn’t change that often anymore. A cold phase: optimized for cost saving over search performance. In this phase the data is read-only. A delete phase: deletes the data you longer need Let’s see how to configure a lifecy...

GraphQL–Discriminated unions for input types through OneOf

Today I want to show you how you can use discriminated unions for input types in GraphQL through the OneOf specification. Disclaimer: The OneOf specification is still in draft, so it is possible that it will still change or not become a part of the GraphQL specification. Let me first start by explaining the use case where I want to apply this features. In our GraphQL api , we have multiple root queries that can be queried either through the technical id(an integer) and the business key(a string). Our original API looked something like this: A consumer of this API should either use the id or the business key but I could not prevent the user from using both: To handle this situation I throw an error when the user tries to invoke the GraphQL query providing both arguments: This is a perfect case that can be improved through the usage of OneOf. By using OneOf on an input object we tell GraphQL that only one field of the input object can be set. In a schema first approac...

Property based testing in C#–Part 4

In this multipart blog post I want to introduce you in the world of property-based testing and how to do this in C#. In the first part , I gave you an introduction on what property-based testing is, why it useful and how it can help you write better code. In the second post , I showed you a concrete example on how to start writing property-based tests in C# using FsCheck . In a third post I explained how property-based tests can help  to find edge cases and to understand a codebase better. In this post I continue the journey by having a look at how to write our own generators. If you didn’t read my previous post, generators are the tool that helps you to select a value from an interval. For some of the available types in .NET, a default generator (and shrinker) exists but sometimes it is necessary to create your own generators. Create your own FsCheck generator in C# Creating your own generator for FsCheck is easy in C#, the only thing you need is a public static class wi...

Nullable reference types–Using the required keyword in C# 11

A few years ago with the introduction of Nullable Reference Types in C# 8, I blogged about a way to get rid of the CS8618 compiler warning for your DTO’s and ViewModels. The trick I shared was to use a a property assignment with a default literal : Although this  solution works it defeats the point of nullable reference types, as the idea is it would help you to get rid of unexpected NullReferenceExceptions. Instead the only thing you got is a compiler that no longer complaints. With the release of C# 11, a better solution exists through the usage of the required modifier . The required modifier indicates that the field or property it's applied to must be initialized by all constructors or by using an object initializer . Let’s update our code: Now the compiler expects that the property is always set, so the compiler warning disappears. Remark : The required modifier is enforced at compile time. So it is still possible that we end up with a NullReferenceExcep...

The future of programming

To end the week, I want to share a talk that really makes you think about the state of the software industry today; "The Future of Programming" When you look at the video above, you would first think that it is a presentation from 1973. Bret Victor who gives the talk, is dressed like an engineer from the 70s, white button-up, khakis, pocket protector. He starts giving his talk using an overhead projector. But as the presentation progresses knowing that we are in 2013 when he gave the presentation, you start to realize how the software industry isn’t so progressive as we may think. Ouch! For me the most important quote of his presentation is at the end: The most dangerous thought that you can have as a creative person is to think that you know what you are doing because once you think you know what you’re doing you stop looking around for other ways of doing things. Food for thought…

Property based testing in C#–Part 3

In this multipart blog post I want to introduce you in the world of property-based testing and how to do this in C#. In the first part , I gave you an introduction on what property-based testing is, why it useful and how it can help you write better code. In the second post , I showed you a concrete example on how to start writing property-based tests in C# using FsCheck . Today I show you how I use property-based tests to find edge cases and can help to understand a codebase. Along the way I’ll share some of the other features that FsCheck has to offer. And to give you a more realistic example, I will use an open source library created by a colleague(thanks Willy for allowing me to use your library as an example); https://github.com/WilvanBil/NationalRegisterNumber . National Register Number is a package that can generate and validate Belgian national register numbers. The logic is based on Official Documentation by the Belgian Government The library is small and offers 2 AP...

How to set the package version when using dotnet pack

With the dotnet pack command you can build a project and create a Nuget package. By default, when you execute this command the package version will be set to 1.0.0 . If you want to specify the package version you can either set the Version or the PackageVersion in your csproj file: If you are using the Version parameter both the FileVersion of the embedded dll and the NuGet package version will be updated. Using the PackageVersion will only impact the version number of the NuGet package. By default, PackageVersion takes the same value as Version. You can override the package version at pack time by using the PackageVersion parameter : dotnet pack /p:PackageVersion=1.2.3-beta It is also possible to set a VersionPrefix and VersionSuffix . The VersionPrefix allows you to set a “base” version number. This can be combined with a VersionSuffix to create the final version. For example, when you set the VersionPrefix to 1.2.3 and VersionSuffix to beta , the Version wi...

NHibernate–Using record types

At one of my customers, we have been using NHibernate for a really long time. And although I think that with the latest Entity Framework Core, the feature set is almost on par, we are still using NHibernate today. Of course, we want to use the newest C# features including Record types . Let’s see if (and how) we can use record types in combination with NHibernate. Here is a simple record type using positional parameters: And the mapping code using Fluent NHibernate: If we try to use this type in our application, NHibernate starts to complain with the following error message:    ---- NHibernate.InvalidProxyTypeException : The following types may not be used as proxies:     Tests.Domain.Category: type should have a visible (public or protected) no-argument constructor     Tests.Domain.Category: method Deconstruct should be 'public/protected virtual' or 'protected internal virtual'     Tests.Domain.Category: method...

Property based testing in C#–Part 2

In this multipart blog post I want to introduce you in the world of property-based testing and how to do this in C#. In the first part , I gave you an introduction on what property-based testing is, why it useful and how it can help you write better code. In this second post, I’ll show you a concrete example on how to start writing property-based tests in C#. Writing the tests Let’s start with the same example as in our previous post and write corresponding tests that checks the properties we have identified. Here is the Add method we wanted to test: These were the properties we identified: Property 1: It doesn’t matter in which order we provide the x and y input, the output is the same. E.g. 1+7 is the same as 7+1 Property 2: Having zero as either the x or y input is the same as doing nothing (the output doesn’t change). E.g. 7+0 =  7 or 0+7 = Property 3: If I call the add method multiple times, the order in which I do the...

Property based testing in C#–Part 1

In this multipart blog post I want to introduce you in the world of property-based testing and how to do this in C#. In the first part(this one), I’ll give you an introduction on what property-based testing is, why it useful and how it can help you write better code. In a second post, I’ll show you a concrete example on how to start writing Property based tests in C#. Disclaimer: Property-based testing is hard! And although I would strongly recommend it for critical parts of your codebase, I would certainly not use it everywhere. What is Property-based testing? Property-based testing was introduced in 2000 by Koen Claessen and John Hughes via the Haskell library QuickCheck . Mark Seemann uses the following definition in his Pluralsight course on Property based testing: Property-based Testing is an automated testing technique where you incrementally zero in on the correct behavior of a system by describing its properties or qualities in general terms and then use randomly...

Azure DevOps Server - Switch from HTTP to HTTPS–Part 4

With the release of Azure DevOps Server 2022 , I thought it would be a good time to finally make the switch to HTTPS for our internal Azure DevOps server. With the idea to minimize downtime, I decided to first introduce the HTTPS endpoint before upgrading the Azure DevOps server. But o boy, what I thought would be an easy task turned out to be quite a journey. In part 1 I explained the steps that should be done at the server side, in part 2 I continued with an explanation of the changes done on the client side. In the third and what I thought would be the final part I had a look at the errors I got on the build server. But here I'm back again with a fourth part, and yes I promise this will be the last one. Although I thought I had fixed everything, I got another error when I tried to build an application(both in Visual Studio and through the Azure DevOps build pipeline). I first noticed the problem when building through Azure Pipelines, here is the error I got: It seem...

Software Engineering at Google ebook available for free

Today I noticed the following announcement in my news feed: The digital HTML version of the “Software Engineering at Google” book curated by Titus Winters, Tom Manshreck and Hyrum Wright is now available for free . This book talks specifically about the software engineering practices and how it is a lot more than programming. The short summary from the O’Reilly website : Today, software engineers need to know not only how to program effectively but also how to develop proper engineering practices to make their codebase sustainable and healthy. This book emphasizes this difference between programming and software engineering. How can software engineers manage a living codebase that evolves and responds to changing requirements and demands over the length of its life? Based on their experience at Google, software engineers Titus Winters and Hyrum Wright, along with technical writer Tom Manshreck, present a candid and insightful look at how some of the world’s leading practiti...

Improve the performance of your web applications by adding one attribute

Images are critical for every website and web application today. As images can be quite large, they can have a big impact on the percieved performance (and than I don't even mention the bandwith cost). Before you start converting all your images to the webp format or implementing all kind of crazy javascript and css hacks, I’ll learn you a simple trick that could help you a lot… You can lazy load your images using the loading attribute.  By using lazy loading, the images in your application or site will only be loaded when they become in reach of the visible are of your website. So as long as a user doesn’t scroll, only what is visible at that moment will be loaded. Here is a simple example: <img src="example.jpg" loading="lazy" alt="..." /> The following values are supported by the loading attribute: lazy - Deferring the loading of assets till it reaches a certain distance from the viewport. eager - loading the assets ...

MassTransit–Using RabbitMQ Virtual Hosts

Today I want to talk about a specific feature in RabbitMQ and how we can use this feature with my favorite messaging library MassTransit. Virtual Hosts With virtual hosts you can create a logical grouping in  your RabbitMQ cluster. Every exchange, queue, binding, user permissions, and so on is bound to a specific virtual host and isolated from the other virtual hosts. This helps to avoid naming collisions. There is always at least one virtual host in use; the default one is ‘/’. To create a new virtual host in your RabbitMQ cluster, you can use the rabbitmqctl 's add_vhost command: rabbitmqctl add_vhost development Or you can use the RabbitMQ Management portal: In the Management Portal go to the Admin tab and click on the Virtual Hosts section on the right: Go to the Add Virtual Host form and enter a name and an optional description and tags : Click on Add virtual host to create the new virtual host. Remark: Be aware...

Azure DevOps Server - Switch from HTTP to HTTPS–Part 3

With the release of Azure DevOps Server 2022 , I thought it would be a good time to finally make the switch to HTTPS for our internal Azure DevOps server. With the idea to minimize downtime, I decided to first introduce the HTTPS endpoint before upgrading the Azure DevOps server. But o boy, what I thought would be an easy task turned out to be quite a journey. In part 1 I explained the steps that should be done at the server side, in part 2 I continued with an explanation of the changes done on the client side. I thought that the job was done but then I got a phonecall about the build server being offline. So in this third and final part we have a look at the errors we got on the build server and how we fixed them. Update build agents When I logged in on the build server, I noticed that all agents were offline. In the logs I found the following error message: [2022-12-20 09:48:01Z INFO RSAEncryptedFileKeyManager] Loading RSA key parameters from file D:\b\3\.credentials_rsap...

Azure DevOps Server–Switch from HTTP to HTTPS–Part 2

With the release of Azure DevOps Server 2022 , I thought it would be a good time to finally make the switch to HTTPS for our internal Azure DevOps server. With the idea to minimize downtime, I decided to first introduce the HTTPS endpoint before upgrading the Azure DevOps server. But o boy, what I thought would be an easy task turned out to be quite a journey. Yesterday I explained the actions required on the server side, today we move on to the client side. Visual Studio TFVC workspaces In Visual Studio, we have to update our connections in Team Explorer. Therefore click on the green Connect icon in Team Explorer . Click on Manage Connections and Connect to a project… Right click on the existing connection and choose Remove from the context menu. Click on Add TFS server , enter the updated Server URL and click on Add . Restart your Visual Studio instance. After doing these steps, I noticed that still the original URL was shown when I re...

Azure DevOps Server–Switch from HTTP to HTTPS–Part 1

With the release of Azure DevOps Server 2022 , I thought it would be a good time to finally make the switch to HTTPS for our internal Azure DevOps server. With the idea to minimize downtime, I decided to first introduce the HTTPS endpoint before upgrading the Azure DevOps server. But o boy, what I thought would be an easy task turned out to be quite a journey. Updating IIS Let’s start with the simple stuff and update our IIS instance to introduce a second binding: Log in on your Azure DevOps server instance. Open the Internet Information Services (IIS) Manager. Select the Azure DevOps Server site on the left and click on Bindings… on the right. On the Site Bindings window choose Add… On the Add Site Binding window, select HTTPS from the Type dropdown and select the correct SSL certificate . Optionally you can also set a hostname. Click OK and Close . Now you can already test if the new binding is working by browsing to the HTTPS...