I'm not saying it was built with Azure Functions, but it was definitely built with Azure Functions.

How to fix “Microsoft.WindowsAzure.Storage: Server encountered an internal error. Please try again after some time.” when using IoTHub trigger for Azure Functions?

One more article before Christmas! 😁 This time, I’ll be fixing a function that’s triggering based on new messages received through my IoT Hub in my Azure Functions project. Technically speaking, this is super simple to implement – your function needs to define an IoTHubTrigger, with an Event Hub name and usually a Connection String (I don’t know why I’m Sentence Casing that, too, but I’ll stick to it!) You can tap a practically unlimited number of Azure Function triggers to any Event Hubs (or…Continue reading How to fix “Microsoft.WindowsAzure.Storage: Server encountered an internal error. Please try again after some time.” when using IoTHub trigger for Azure Functions?

Azure DevOps - Always Be Shipping!

How to authenticate against npm registries in Azure DevOps?

Another one in the series of “this should’ve been easy, but alas, you’re the edge case”. “You” being “me”, and the “edge case” being our internal npm feed (registry), for whatever reason. Ah, well – life would be extremely boring if everything always went according to documentation, right? So, instead of the built-in ways to access npm feeds, this solution includes some PowerShell. Ah – that’s when you know it’s going to be good, right? When someone goes as far as to throw away the…Continue reading How to authenticate against npm registries in Azure DevOps?

SignalRRRRRR meme. Fantastic use of my web hosting storage.

How to test SignalR-connection in the browser?

So a while back I posted about testing your “vanilla” WebSockets connection directly in the browser – and while that’s nice and easy, sometimes you need to class up a bit. In my case that meant upgrading to SignalR (for some corporate and enterprisey reasons as usual). It makes sense to leave behind the easy, simple, lightweight and somewhat transparent websockets to “upgrade” to the enterprise-ready (and arguably quite a lot less transparent) SignalR? Well – I went through that, and since I needed to…Continue reading How to test SignalR-connection in the browser?

Azure Key Vault logo

How to update from deprecated Microsoft.Azure.Services.AppAuthentication to new and shiny Azure.Security.KeyVaults.Secrets?

So, a while ago I posted about a fairly simple way to write your code for fetching secrets (and other confidential stuff) from Azure Key Vault in such a way, that it would work the same way both in Azure and on your local dev box. I find this pretty important, as it reduces the need for weird workarounds and fallbacks in your code, and at the same time enables you to harness the Azure Key Vault for that sweet spot of “good enough security…Continue reading How to update from deprecated Microsoft.Azure.Services.AppAuthentication to new and shiny Azure.Security.KeyVaults.Secrets?

Azure Functions CLI - such a pretty logo for such an awesome functionality

How to fix “Unable to cast object of type ‘System.Net.Http.HttpRequestMessage’ to type ‘Microsoft.AspNetCore.Http.HttpRequest’.”

This article explains how to fix an issue where your Azure Functions function (yes, that’s a capital F and a lowercase f to denote the difference between the product and the piece of compute) fails to fire when a POST request comes in, even though it’s configured to do so, and instead throws a somewhat confusing error message about HttpRequestMessage not being castable to HttpRequest – even though you KNOW HttpRequestMessage works just fine for receiving POST requests with payload! So, why is this happening…Continue reading How to fix “Unable to cast object of type ‘System.Net.Http.HttpRequestMessage’ to type ‘Microsoft.AspNetCore.Http.HttpRequest’.”

Azure Key Vault logo

How to authenticate against Azure Key Vault both in Azure and local development environment?

Azure Key Vault is great. But when developing locally, it can be a bit of a pain. You can always circumvent it and create some classical solution, like wrapping all of your key/secret assignments in if-else-clauses that will use local configuration if you’re running locally and only call the Azure Key Vault if you’re in the cloud… But that feels so incredibly early-2000-ish. Isn’t there a better option available? I mean – obviously, there is! And we’ll see how it works in just a while…Continue reading How to authenticate against Azure Key Vault both in Azure and local development environment?

Azure CosmosDb logo

System.Text.Json.JsonPropertyName not working for CosmosDb in .NET Core/5?

This article explains how to fix an annoying issue with Microsoft’s SDK for CosmosDb v3 – it comes with a Newtonsoft.Json dependency, that most of Microsoft’s recent packages have let go of. With .NET Core 3.1 having shipped with System.Text.Json included, and (mostly) replacing Newtonsoft.Json, it’s kind of the preferred option. However, CosmosDb v3 SDK doesn’t support it and by default requires you to use Newtonsoft.Json to override the property names, if you want to – for example – map entities with PascalCase naming with…Continue reading System.Text.Json.JsonPropertyName not working for CosmosDb in .NET Core/5?

Some men want to watch the build fail

Errors loading an assembly that’s using Microsoft Graph API

Man, do I run into all kinds of issues with the smallest Azure Functions that I develop. And it’s mostly my fault. The silver lining is that you’re here to read this article, so you probably ran into this same stuff. Well – you should be happy to hear this article describes fixes to a couple of issues – let’s see if they help you out as well! The article probably largely applies to any situation where you have a project referencing another project and…Continue reading Errors loading an assembly that’s using Microsoft Graph API

EF Core equals bonk - a quality Entity Framework meme right there.

“dotnet ef script” or “Script-Migration” producing empty .sql files?

Another day, another issue. This time, I was absent-mindedly following the guidance for a project on how to generate .sql files for .NET EF Core code-first migrations. Don’t ask why that was required, but it was. My migration was simple. Adding an entity with just a few properties. And Entity Framework created my programmatic migration just fine. But when generating the SQL file, I got nothing but an empty file. No matter what was my startup project, working directory, context, target folder, or other variables…Continue reading “dotnet ef script” or “Script-Migration” producing empty .sql files?

T-SQL, yes please!

How to form a parameterized SQL query to find duplicates in a table.

So one day, I needed to quickly check if an identity field in a view in a Microsoft SQL Server was actually unique or not. I was running into weird issues with Entity Framework throwing an error somewhat like this: Store update, insert, or delete statement affected an unexpected number of rows (2) Or somewhat like this: Type: DbUpdateConcurrencyExceptionStore update, insert, or delete statement affected an unexpected number of rows ([row count]). Entities may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=472540…Continue reading How to form a parameterized SQL query to find duplicates in a table.

C# & .NET

How to serialize to JSON in camelCase using .NET Core?

This article describes how to configure your .NET Core application to serialize objects in camelCase instead of PascalCase. I guess this is another quick note – something that should be simple, but I couldn’t remember how to do it from the top of my head, and the solution turned out to be a bit unintuitive. I guess that makes it worth documenting because I’ll run into this again for sure. Anyway – let’s take a closer look at the actual issue at hand, shall we?…Continue reading How to serialize to JSON in camelCase using .NET Core?

401 Unauthorized meme

How to secure your WebSocket connection using .NET Core?

This article explains how to easily authenticate your WebSocket connections using .NET Core and vanilla JavaScript. The same concept probably applies to all sorts of front-end libraries, although some of them might offer some syntactic sugar on top of it. But it’s simple, and keeping your implementation simple is generally speaking a good idea. So – this one came up when developing a simple API that’d expose a WebSocket endpoint for seamless notifications to the Web UI. As everything else in the system required authentication,…Continue reading How to secure your WebSocket connection using .NET Core?

WebSockets.

HttpContext.WebSockets.IsWebSocketRequest always null in .NET Core?

This article explains another simple fix to an annoying issue. I guess that’s how I start like every other one of my little tutorials, but hey, it’s true! I suppose I just have a knack for running into issues that come with poorly documented fixes or workarounds that are obvious but only in hindsight… Right? Anyway, this time my WebSocket requests were not being handled as such by my ASP.NET Controllers. “IsWebSocketRequest” was suggested by IntelliSense, but it would always be null in the code.…Continue reading HttpContext.WebSockets.IsWebSocketRequest always null in .NET Core?

WebSockets.

How to test a WebSocket connection in a browser

This article documents a simple and neat way to establish and test a WebSocket connection, using just vanilla JavaScript and your favorite browser’s developer tools. Quick and easy – no external tools or libraries required! This is neat because you don’t want to have your information (credentials, hostnames, or even test data) leaking to outsiders hosting the tools. In the sample I’ll show just a few paragraphs below, we’ll instantiate a websocket connection, hook a listener to the onmessage event and the last line sends…Continue reading How to test a WebSocket connection in a browser

Powershell is hell

Solving “Unable to find repository ‘https://www.powershellgallery.com/api/v2’.”

So, you’re running a PowerShell command that requires a connection to PowerShell gallery, but you run into an error message, somewhat like this: “Unable to find repository ‘https://www.powershellgallery.com/api/v2’. This can happen when you’re running something like Install-Module or Update-Module. This pretty much blocks you from doing anything that would require the use of new modules – so, quite a lot. Worth fixing, then. 😁 Problem The whole error message might be somewhat like this: What gives? Posts Related to “Solving “Unable to find repository ‘https://www.powershellgallery.com/api/v2’.””:How…Continue reading Solving “Unable to find repository ‘https://www.powershellgallery.com/api/v2’.”

Better blame TLS 1.0 for this one.

How to force an outdated .NET project to use TLS 1.2?

This article explains a kind of weird fix to a pretty annoying issue with a legacy service. And I’m not just calling it legacy because it’s WCF – I’m calling it legacy because it’s old. The particular piece of software was developed about 7 years ago (2014-ish)! It had worked for quite a while – but now it was down. I know, I know – 2014 is not THAT old. There’s surely COBOL that’s been running since the 70s, if not before. But in the…Continue reading How to force an outdated .NET project to use TLS 1.2?

While only a few countries use absurd date formats (such as the Month-first approach adopted by some former European colonies), there's no shortage of different date formats out there. Source: John Harding/Mona Chalabi

Experiment: DateTime formats

This article explains how to loop through all supported cultures on any given machine that’s able to run .NET. The code sample is in C# and outputs an HTML table you can copy – but obviously you can adapt it to your needs! This was something I needed to support some weird documentation task way back when – and it took me like a year to finish this blog post and push it out from the drafts… Background Okay. So I needed to figure out…Continue reading Experiment: DateTime formats

Visual Studio logo

How to fix a build configuration that’s not available as a build directive in Visual Studio?

This article describes how to fix and tweak your pre-build directives in Visual Studio – just in case they refuse to work properly. Because yeah, apparently that sometimes just randomly happens. But fear not – there’s a stupid and ugly, but definitely thoughtful workaround available! Also, sorry for the confusing title. I’m taking suggestions for a more descriptive one – but this one was kind of difficult to word clearly. Anyway – on to the topic of the day! Problem So you’re either trying to…Continue reading How to fix a build configuration that’s not available as a build directive in Visual Studio?

Entity Framework Core logo

Fixing “No database provider has been configured for this DbContext” in Entity Framework Core

I’m using Entity Framework in most of the projects that I’m working on – and for the most part, it’s a pleasure to work with. But as always, there are plenty of chances to run into issues – so obviously, I stumble into all of the rare stuff that IS broken! This one I hadn’t really seen before – “No database provider has been configured for this DbContext”. This time I encountered the issue while setting up a new project and getting started working on…Continue reading Fixing “No database provider has been configured for this DbContext” in Entity Framework Core

Azure Functions CLI - such a pretty logo for such an awesome functionality

How to fix “Missing value for AzureWebJobsStorage in local.settings.json” when you’re debugging Azure Functions locally?

Another day, another issue with Azure Functions! For such a simple and powerful tool, it sure does produce a lot of topics for blog articles! 😁 So let’s get down to fixing another Azure Functions configuration issue. But wait – what WAS the problem again? Problem When firing up your Azure Functions project locally, this error is what you’re confronted with: “Missing value for AzureWebJobsStorage in local.settings.json. This is required for all triggers other than httptrigger, kafkatrigger. You can run ‘func azure functionapp fetch-app-settings ‘…Continue reading How to fix “Missing value for AzureWebJobsStorage in local.settings.json” when you’re debugging Azure Functions locally?