A Rose By Any Other Name - Short Circuiting
Suppose you have the following C# program:
Using Inheritance With FluentValidation
If you are a .NET developer, you really need to be using the FluentValidation library.
Dogs Will Always Bark - Part I - You Make I Check
If you have not already, you will, inevitably, run into a system that has a concept of a maker and a checker.
Correctly Setting HttpClient BaseAddress
To make HTTP requests in C# (or any other .NET language), you use the HttpClient class.
How Long Is A String
Take any software in popular use:
Verifying File Hashes With PowerShell (Update)
A couple of years back I wrote a post of how to get the hash of a file natively in PowerShell in situations where you need to verify a download, like this one:
Tip - Don't Log Exceptions With Log.Information
When it comes to logging, many ILogger implementations allow you to log errors like this:
Did You Know - An Email Body Is Optional
The other day while working with one of our internal libraries for sending email, I ran into an error where it complained about a missing body.
Defining Relationships With Enum Attributes For Enum Values In C#
Suppose you had the following enum
Tip - Using JsonSerializationOptions With Refit
Refit is an excellent library that makes it very easy to call APIs are convert the responses to typed objects.
Fix - HttpClient Changes Case Of x-request-id Header
When working with a HttpClient, this is how you add a request header to each request:
Projecting Named Tuples In Entity Framework Core
Suppose you had the following class:
Tip - Fluent Validation With Null Values
There is an excellent library, FluentValidation, that is very handy when it comes to expressing validation logic, and doing it centrally.
Accessing SQL Server Configuration Manager
Once in a while you might need to access the SQL Server Configuration Manager.
Why Doesn't Windows Have A Built In Dictionary?
“Why,” a CEO friend of mine asked one day in exasperation “doesn’t Windows have a dictionary?”
Writing Maintainable, Testable Code That Depends On The Current Time
Code that is conditional on time is almost something you are guaranteed to write at some point. Think:
How To Use C# List Pattern Matching Practically
One of the more powerful features introduced in C# 11 is list pattern matching.
Building Directory Paths In C#
Suppose you wanted to generate a folder on your desktop, say to store your incomplete proposals.
Writing A Custom DateOnly JSON Deserializer
The versatility of JSON as a data interchange format is that it can represent almost anything, given that ultimately all attributes are strings (or numbers).
Stop Press - Running Linux GUI Applications In Windows
So very quietly last week a game changer was published to the Windows Appstore.
How To Index A NVarchar(MAX) Table In SQL Server
Suppose we have this table:
Handling Null And Empty Strings With System.Text.Json - Part 2
In a previous post I talked about Handling Null And Empty Strings With System.Text.Json
Enabling TCP/IP For SQL Server
Access to the SQL Server database engine is achieved using one of three protocols.
Required Keyword In C# 11 & .NET 7
One of the improvements in .NET was the record.
Tip - SQL Server Management Studio - Constructing Dates
Working with dates is a fairly common operation when working in TSQL.
Tip - SQL Server Management Studio - Reorder Lines
Most of your time when working with the SQL Server Management Studio you will be writing and modifying queries.
Tip - SQL Server Management Studio - Duplicate Tab
Suppose you have this query:
Tip - SQL Server Management Studio - Server Colouring
We’ve all done it - ran a query on the server we thought was the test but was in fact the production
Tip - SQL Server Management Studio - Reorder Results
Working with results is one of the most obvious use cases of SQL Server Management Studio.
Microsecond Precision In .NET
The traditional way to make a DateTime is as follows:
How To Order Classes And Records In C#
When it comes to collections of primitive types, ordering is pretty straightforward.
Tip - Simpler LINQ Ordering In .NET 7
Using LINQ, you can order a collection using the OrderBy (or the OrderByDescending) extension methods.
Tip - Using LINQ To Filter A List Of Strings Containing Words In Another List
Suppose you have this list of snacks.
Tip - Grouping Correctly In LINQ With VB.NET
Grouping is one of the more powerful features of LINQ.
Building URLs In C# Without Concatenation Or Interpolation
When dealing with the web, you will often require to deal with URLs.
Using HttpClient To Post JSON In C# & .NET
For a long time if you wanted to post JSON using a HttpClient, you would do it like this:
Punched In The Face Or In The Stomach
Quick - would you like to be punched in the face or punched in the stomach?
Conmen, Charlatans And Software Developers
Three of the things you will quickly discover that you need in this business are the following:
- A tough skin
- Patience
- An ability to accept an ambiguous state as a valid reality
Beware - Mapping Inherited Immutable Classes Using Dapper
Assume you have the following class:
Linux Tools Packaged With Windows
If you are running a recent build of Windows 10 (or 11) you would be surprised to learn a number of tools traditionally found in Linux are now bundled with Windows.
Fix - Python - Warning- Ignoring Invalid Distribution
When doing pip update
or pip list
you might get the following warning:
Fix - SSL Provider, error 0 - The certificate chain was issued by an authority that is not trusted
For many years, the provider to access SQL Server from .NET was System.Data.SqlClient.
About curl And PowerShell
In a previous blog post I had talked about how curl
in Powershell was an alias for the Invoke-WebRequest cmdlet.
Adding Multiple Items To A HashSet In C#
Let us take a typical object:
What Amazon AWS Local Zones Mean For ICT In Kenya
Amazon AWS announced the other day that they were setting up an AWS zone in Nairobi.
Tip - HttpUtility.UrlEncode vs WebUtility.UrlEncode
In this world of websites and APIs you will invariably be called upon to build URLs, either manually or through code.
Tip - Updating The Nuget Client
Did you know that the Nuget client (nuget.exe
) is capable of updating itself?
Cleaner Code With Switch Expressions In C#
Everyone who remembers their path towards becoming a programmer, either as a hobbyist or a career software engineer, will remember the problem of writing this program - given a mark, allocate a grade according to a table like this:
Fetching Table Data From Web Pages Using Excel
Microsoft Excel is like that old, dependable, reliable friend that always has a solution to your problems.
If Your Grandmother Had Wheels - She Wouldn't Be A Bicycle - Its ALWAYS Harder Than You Think
“I have an idea!” a friend said breathlessly.
Using 'TRUE' and 'FALSE' For Bit Types In SQL Server
SQL Server, as you are no doubt aware, has a type that can be used to represent boolean states - true
and false
.
Maintainability Of Code
The problem is simple.
Standing In A Garage Doesn't Make You A Car - Why You Cant Just "Hire Developers"
Coding Is Easy - Any Monkey Can Do It. Software, However Is Very Hard
There is a famous question those in the software industry ask themselves:
All Sons Are Handsome; All Daughters Are Beautiful - Pitching Enterprise Software
In my experience, parents are generally of the opinion that their sons are handsome and their daughters are beautiful.
30 Days Of .NET 6 - Day 30 - Simplified Argument Null Checks
One of the things you will quickly learn after doing software development for any amount of time is that you cannot assume users of your software will do the right thing.
30 Days Of .NET 6 - Day 29 - Writing Raw JSON Using Utf8JsonWriter
Serialization of objects to JSON, as we have seen, is easily achieved using the native Json serializer, System.Text.Json.
30 Days Of .NET 6 - Day 28 - JSON Serialization To & From Streams
Most of the time, when serializing JSON, you already have access to the underlying object that you are serializing.
Tip - SQL Server User Defined Table Types - Column Order Matters
User Defined Table Types are a very nifty way to pass data to a stored procedure for processing.
30 Days Of .NET 6 - Day 27 - Extended Property Patterns
Pattern matching is a powerful feature borrowed from functional languages that can make a whole class of problems simpler to solve.
30 Days Of .NET 6 - Day 26 - Sealed ToString() In Records
One of the things you get for free when using a record
is that the compiler will write for you a ToString()
method for free.
30 Days Of .NET 6 - Day 25 - Hot Reload
Programming has been with us for almost a century now but the cycle surprisingly has largely been the same:
.NET 6 Release
The final release of .NET 6 is now available.
You can get the final bits here. Remember that .NET is cross platform so you can select the appropriate sections to download the bits for your operating system
30 Days Of .NET 6 - Day 24 - Parallel.ForEachAsync
Computing “power” over the past decades has changed from being a speed game “megahertz” to a parallelism game - multi-processor, multi-core.
30 Days Of .NET 6 - Day 23 - Nullable References
The great computer scientist Tony Hoare, credited with inventing the null
reference, famously confessed this to be his ‘billion dollar mistake’.
30 Days Of .NET 6 - Day 22 - LINQ Default Parameters
One of the things to think about when writing LINQ
filter expressions (First
, Last
, or Single
) is what happens when the thing you are looking for was not found.
30 Days Of .NET 6 - Day 21 - Constant Interpolated Strings
A fairly common task in day to day programming is combining strings.
30 Days Of .NET 6 - Day 20 - Json Property Ordering
Today we look at what might be a niche feature, but nevertheless in some use cases might actually be quite useful.
Saving Collections Of Primitives In Entity Framework Core
Suppose you have the following class that you wish to persist using the Entity Framework Core ORM.
30 Days Of .NET 6 - Day 19 - Record Structs
Today’s item, record structs
, is a bit more elaborate to explain, but I shall do my best.
.NET 6 Release Candidate 2 Out
.NET 6 Release Candidate 2 was released last week, on the 12th.
30 Days Of .NET 6 - Day 18 - File Scoped Namespaces
As your codebase grows, it becomes important to organize your code. This is done using a concept called namespaces.
30 Days Of .NET 6 - Day 17 - New Timer - PeriodicTimer
If there is one thing that .NET has plenty of it is timers.
30 Days Of .NET 6 - Day 16 - HTTP/3 Support
The Hypertext Transfer Protocol is the protocol at the heart of the internet.
Installing .NET 6 On Linux
It is again worth repeating that .NET 6, like 5, 3 and 2 before it are cross platform and can be used to build applications in Linux and OSX.
30 Days Of .NET 6 - Day 15 - SOCKS Proxy Support
Occasionally you will need to connect to the internet, or to another network for that matter, through a proxy.
30 Days Of .NET 6 - Day 14 - Implicit Usings
When developing an application, you invariably will need to use logic or functionality encapsulated elsewhere.
30 Days Of .NET 6 - Day 13 - LINQ Improvements - Chunk
One of the cornerstones of modern computing is that there is much less emphasis on raw power and more on distributing work.
30 Days Of .NET 6 - Day 12 - Collection Count Performance Improvement
UPDATE
30 Days Of .NET 6 - Day 11 - LINQ Improvements - Range Support
One of the most powerful features of LINQ is the ability to select a range of elements from a collection.
30 Days Of .NET 6 - Day 10 - SDK & Runtime Version Checking
Software is always a moving target - adding features, fixing bugs or even removing features. The same challenges fall upon the tools used to develop software.
30 Days Of .NET 6 - Day 9 - LINQ Improvements - DistinctBy
Another improvement that has been added to the LINQ engine is the DistinctBy method.
30 Days Of .NET 6 - Day 8 - Control Of Serialization Of Object Cycles
When dealing with complex object graphs in memory, it is common to have objects referencing themselves.
.NET 6 Release Candidate 1 Out
The .NET 6 Release Candidate 1 was released last week.
30 Days Of .NET 6 - Day 7 - Simpler Web Application Development
The default template for a web application in .NET 5 and previous versions looks like it was done with seasoned, disciplined developers in mind. This is not a bad thing. The issue, just like with the previous console templates I’ve talked about earlier, is it is not welcoming to those new to the platform.
30 Days Of .NET 6 - Day 6 - Priority Queue
We are all familiar with the Queue class.
30 Days Of .NET 6 - Day 5 - Mathematics API Additions
It may surprise you to learn that even the Math API, which generally does not change all that much, has some additions for those who do high performance trigonometric functions.
30 Days Of .NET 6 - Day 4 - LINQ Improvements - MaxBy & MinBy
One of the most powerful features introduced in the .NET Framework, all the way back in 2008 in .NET 3.5 was Language Integrated Query, better known as LINQ
30 Days Of .NET 6 - Day 3 - TimeOnly Type
We looked at the new DateOnly Type on Day 1 of this series, and it should come as no surprise that there is a companion TimeOnly type that has been introduced to deal with only the time component of a DateTime.
30 Days Of .NET 6 - Day 2 - Friendly To Newcomers
One of the challenges of developing and maintaining a programming languages and its accompanying tooling is you have to be welcoming to several demographics:
- Experienced developers on your tool-set
- Experienced developers from other tool-sets
- Students
- Complete newcomers to programming & hobbyists
30 Days Of .NET 6 - DateOnly Type
In .NET when manipulating dates and times, you generally use the DateTime type for such purposes.
Fix - .NET 6 Not Being Recognized After Install
After installing the .NET 6 SDK you can confirm that it was successfully installed and recognized by running the following command:
About Software Bloat
Occasionally you will hear somebody say, (or you yourself may say) something like:
Fix - Docker Error On Upgrade - aufs storage
While upgrading docker you may get the following error:
Fix - Unavailable Resource Error When Posting HTTP Request To Teams
I have done two posts on automating posting messages to teams.
Tip - Get Current Date In C#
Frequently in the course of your code, you will need to get the current date.
Reducing Bugs And Improving Maintainability Through Better Domain Design
One of my favourite maxims is “measure twice so you cut once”.
Sending Teams Messages Using PowerShell
First, read this previous post that gives a primer on how to interact with Microsoft Teams.
Better Assertion Testing With FluentAssertions
In the .NET world, there are two main unit testing frameworks: XUnit and NUnit.
The Value Of Good Documentation
Recent developments (we are in the middle of a massive upgrade of our technology stacks) as well as strategic decisions have forced us to interface with systems and ecosystems not only at code level as we are accustomed to, but additionally at documentation level.
Beware - F# Doesn't Support C# Types Using Init Modifiers
Our primary stack at Innova is .NET, that we principally historically implemented in C# (and some Visual Basic.NET)
On Career Progression
Lionel Messi is, by many accounts, the best football player in the world.
Tip - Locating Commands In The Path On Windows
Assume you have a command like so:
Tip - TimeSpan Minutes vs TotalMinutes
The TimeSpan object allows for the representations of a point in time (the TimeOfDay component of a DateTime).
The Cost Of Adding Features To Software
More Features Is Good
Fix - Docker For Windows Not Running
Gitlab HTTP Authentication With 2FA
If you have turned on 2 factor authentication for GitLab, you might be wondering how you can access and manipulate your repository over HTTPS.
About Default Interface Impementations
Default interface implementations were introduced in C# 8. Essentially these are interface declarations with bodies.
The Other Integer Types
Most developers when requiring a integer type use the int
type and go about their business.
Tip - Making Use Of Windows Terminal Tab Captions
If you’re on Windows and are not using Windows Terminal, you really should.
Fix For The string argument propertyNames cannot be empty
Today I got the following error when working with Entity Framework Core against a PostgreSQL database:
Disqus Off
So I noticed that the Disqus comments that I’ve been had been displaying a range of scammy ads.
Using System.Text.Json To Enforce API Logic
Assume you have the following type:
Deleting RabbitMQ Queues With EasyNetQ
I recently had to delete all the queues in my RabbitMQ instance.
Fix For Cannot use LINQ in MatchCollection Regex with .NET Standard 2
I have some code where I am running a regex and using LINQ to manipulate the matches.
Handling Null And Empty Strings With System.Text.Json
Assume we have the following class:
Inheritance In Business Logic Is Likely A Code Smell - Part 1
When you were introduced to object oriented programming (OOP), you probably used the canonical example domain of animals.
Handling Exceptions With Refit
Refit is a very brilliant library that allows you to call REST APIs with minimal code.
Consuming REST JSON APIs From Excel
So today I wanted to see if Excel could natively consume JSON APIs.
Fix - error CS8805 Program using top-level statements must be an executable
So today in a rather large project I began getting the following error when I ran a build:
Using Regex MatchEvaluators In C#
Regular expressions (Regexes
) are a powerful tool for solving certain types of problems - and in particular looking for a certain pattern of text in a larger string and (optionally) replacing it with another.
Remember To Encode QueryString Data
Assume you have a controller with this GET
end point
Be Clearer With TimeSpans
Many of the .NET APIs take time intervals as their parameters, and it usually is in milliseconds.
Entity Framework Core - Unique Constraits vs Unique Indexes
In your traditional database, there are two ways to enforce the restriction that “the value of this column should be unique”:
- Unique constraints
- Unique indexes
UI Fails - Oracle VirtualBox 6.1
This is the dialog I saw when I launched Oracle VM VirtualBox today.
Fix For Entity Framework Core Not Generating Indexes & Constraints
If you are using Entity Framework Core, and are configuring your models using configuration classes (as you probably should) you might run into a situation where after adding your migrations and updating your database, you find that the resulting schema does not have indexes or unique constraints.
Fix For Entity Framework Tools Error
While running the entity framework command to add a migration, I got the following error
Fix For pgAdmin Not Loading
Are you attempting to open the pgAdmin web console and it appears to be loading endlessly?
What Do You Actually Agree To When You Accept All Cookies
I have been writing software for exactly twenty years now. In the course of this I have learnt very many things, which I hope to journal over time.
Improving HttpClient Requests
This is another improvement to the logic of making a Http
request using the HttpClient.
Beware of HttpClient Header Validations
I ran into an interesting problem the other day.
Remote Debugging In VS Code
Today we will setup an environment where we can develop and debug code remotely on a Linux environment.
HTTP Redirects Using HttpClient
In a previous post I had mentioned that the HttpClient
does not automatically process HTTP redirects and you would have to write the logic yourself.
Refactoring With Records In C#
I recently had an opportunity to revisit some very old code (to the tune of almost a decade) and saw it as an opportunity to make some improvement and cleanup.
Changing The Default Shell In IntelliJ To PowerShell
The default shell in IntelliJ (and its children IDEs) is the Windows Command Prompt.
Conditional Logic In MSBuild
The Microsoft Build Engine, MSBuild, is responsible for controlling the build process that translates source code to object code and its relevant artifacts.
Getting Now Playing Information From WQXR In .NET
UPDATE: Updated to .NET 7 on 23 Feb 2023
Posting Messages To Microsoft Teams With Code
Microsoft Teams makes use of an API, the Microsoft Graph API, that is leveraged to push data into, and pull data out of various Microsoft Products, chiefly Office 365.
Disable SSL Certificate Validation In .NET
If you are invoking a web request from your application, you may get the following error:
Querying & Extracing Data From YouTrack
YouTrack is a robust web based platform for issue tracking, Sprint and Kanban management.
Chrome UI Surprises
Here is a site I am visiting on Chrome.
Joining Strings - Part 4 : String.Format
This is Part 4 in the series of Joining stings
Joining Strings - Part 3 : StringBuilder
This is Part 1 in the series of Joining stings
Joining Strings - Part 2 : String.Concat
This is Part 2 in the series of Joining stings
Upgrading To WSL 2
Good news if you have been running on Windows Subsystem For Linux (WSL) and have wanted to upgrade to version 2 but have not been willing to join the Windows Insider Program - WSL2 is now out in the main release.
Joining Strings - Part 1 : The + Operator
This is Part 1 in the series of Joining stings
Jekyll, Ruby & OpenSSH
So like I mentioned in my last post, I have migrated from WordPress to Jekyll as my content management system.
Goodbye Wordpress
I have been running this blog on WordPress since inception, and using WordPress in general for many years (since 2005).
Using IIS With ASP.NET Core 3.0
Kestrel, the web server that powers ASP.NET Core is highly optimized for running ASP.NET Core code, and running it fast.
Using Curl In PowerShell
A useful tool to have in your toolbelt is an ability to make web requests and retrieve responses from the command line.
Touch In PowerShell
In Unix / Linux land there is a handy command to create an empty file.
How Old Is Your Language?
Ever wonder how old your favourite language is? You might be surprised!
Decimals, Precision And Scale
The .NET framework has a decimal data type.
Extracting Bytes From A F# String
Suppose you need to extract the byte values of a string in F#
Should all bugs be fixed?
On the surface a perfectly reasonable question.
What Is A Software Company?
A software company is an institution that converts money into software that people pay money for.
Count vs Length vs Any - Checking Collection Emptiness
When working with collections there are several ways that you can determine if a collection is empty.
Getting Your Internet IP Address
Suppose, for whatever reason, you need to know your ISP assigned IP address.
Properties Under The Hood
One of the features of C# (and the .NET platform in general) is the support of properties as a first class citizen of the runtime.
Arguments Handling Across Paradigms
One of the interesting things about using an object oriented language (like C#) vs a functional one (like Racket) is you get an opportunity to see first hand how different things are doing in either paradigm.
FizzBuzz In F#
The FizzBuzz problem is one of those ubiquitous industry problems that has been floating around for decades, intended to separate the sheep from the goats.
Using Nuget In F# Scripts
One of the brilliant improvements in F# 4.7 is the ability to make use of Nuget packages in your scripts.
Pinning Nuget Package Versions
The Nuget package management system has been a godsend when it comes to managing libraries and dependencies in your projects.
Controlling Creation Of .NET Core Projects
Many of us create .NET Core projects in the following way:
Fun With Tuples In C# 7 & Above
Tuples, or to use their correct name, ValueTuples
, were introduced in C#.
Verifying File Hashes With PowerShell
It is often a good idea to verify the file hashes of downloaded files, whether it is to detect that the file you download was actually the one that the developers intended (see what happened to Handbrake for OSX) or to detect corruption of a download.
AsReadOnly() May Not Be Doing What You Think!
You have probably come across the AsReadOnly()
extension method, and have probably made liberal use of it.
Beware Of Controller Name Typos In ASP.NET Core Controllers
The other day I spent the better part of an hour trying to figure out why a particular controller action was not being hit by a request.
Copy SSH Key In Windows 10
Did you know that Windows 10 has a proper SSH client, and has had one for a while?