“No suitable method found to override” error in Blazor/Razor pages

A screenshot of a series of errors in a Blazor application stating "No suitable method found to override"

I’ve run into an issue several times recently while working in Blazor where I’ll innocently try and run the application after some minor changes, only to be hit by a wall of errors seemingly out of nowhere:

ExamplePage.razor.cs(7, 29): [CS0115] 'ExamplePage.OnInitializedAsync()': no suitable method found to override
ExamplePage.razor.cs(12, 29): [CS0115] 'ExamplePage.OnAfterRenderAsync(bool)': no suitable method found to override
ExamplePage.razor.cs(17, 29): [CS0115] 'ExamplePage.OnParametersSetAsync()': no suitable method found to override
ExamplePage.razor.cs(22, 26): [CS0115] 'ExamplePage.SetParametersAsync(ParameterView)': no suitable method found to override

All of a sudden every single Razor component lifecycle function throughout the application is exploding and I’m left wondering how I managed to break things so spectacularly.

My approach to fixing this historically was:

  1. Take a look at my local changes in Git
  2. Try to tweak things to get it working again
  3. Fail
  4. Roll back everything and re-implement the change

It was frustrating and had wasted enough of my time over the past few months that I decided that I was going to figure it out once and for all, by gum.

Note: If you’re in a hurry the fix is quick and simple, so feel free to jump straight down to that section to skip my self-indulgent waffling.

Continue reading ““No suitable method found to override” error in Blazor/Razor pages”

SignalR Messaging Overview: A Look at How It All Hangs Together

A flow-chart representing the route a SignalR message takes through a standard SignalR implementation. A client browser is on the left, with a group called "MVC App" containing a Request Handler and ChatHubInstance. The flow goes starts with the request handler mapping the ChatHubInstance to the endpoint /ChatHubEndpoint. The client then connects to the SignalR hub using the defined endpoint and transmits a "SendChatMessage" message to the hub endpoint, which is translated into an actual procedure called SendChatMessage on the mapped hub. The SendChatMessage procedure then sends a "ReceiveChatMessage" message to all clients, which each invoke their "ReceiveChatMessage" handler on receipt.

SignalR is a fantastic library for enabling real-time applications, especially when using MVC or Blazor in ASP.NET Core. I’ve been using it a lot lately and while it is an excellent way to make your application feel super responsive through messaging and remote procedure calls, there are certain aspects of how the whole thing hangs together which can be very confusing.

This blog post is designed to give you an overview of the different parts of a “standard” SignalR implementation and explain how messages flow through the system. I won’t be going into details on how SignalR works internally (if I even could!), instead choosing to focus on the parts that you’ll come into direct contact with. This blog post also isn’t designed as a tutorial since there is great documentation for implementing SignalR already (which is where I sourced the below code examples from!).

Continue reading “SignalR Messaging Overview: A Look at How It All Hangs Together”

High Potentials Programme 2022 or: How I Learned to Stop Worrying and Love Project Management

A certificate that says "This certificate is awarded to Matthew Champion for the successful completion of the High Potentials Programme July 5th 2022", with logos and signatures from Avado and Blenheim Chalcot

Two days ago I graduated as part of the 2022 cohort of the High Potentials Programme, a 12 week leadership course delivered by Blenheim Chalcot and Avado Learning that looked at change/project management, leading teams and creating commercial value. Fancy.

A certificate that says "This certificate is awarded to Matthew Champion for the successful completion of the High Potentials Programme July 5th 2022", with logos and signatures from Avado and Blenheim Chalcot
I got a (digital) certificate and everything!
Continue reading “High Potentials Programme 2022 or: How I Learned to Stop Worrying and Love Project Management”

You Are Not Your Output

Maybe it’s just me, but if I look at our bug tracker at work one week and see my smiling face attached to a bunch of fixed bugs and implemented features then good lord do I feel chuffed with myself. When I manage to put together a blog post earlier than expected? Oh yeah, I’m amazing.

It’s not bad to feel proud of the things you produce of course, but the issue comes into focus when I look at Jira another week and I’ve only managed to clear a couple of tickets, or I barely manage to scrape together a blog post before the end of the month; my self-esteem plummets.

It’s honestly pretty ridiculous when I write it out like this, but it happens enough that I wanted to really take a look at why this happens. After a bit of introspection, I realised my issue; I’ve been judging myself by my output rather than my input.

Continue reading “You Are Not Your Output”

Allowing Azure DevOps Release Pipelines Access to Remote Artifacts

A screenshot of the Azure DevOps project summary screen with the "Project settings" navigation item highlighted

If you’re using Azure DevOps for your continuous integration/continuous deployment (CI/CD) pipelines you may have stumbled across a pretty cool feature: you can create a build pipeline artifact in one project and import it into the release pipeline of another project! I use this to build a utility once and then import it into several other projects to avoid having to build it several times and trying to maintain settings in multiple places.

The issue is that the first time I tried using this approach, I received the following error:

2022-05-31T06:42:42.2517765Z ##[section]Starting: Download artifact - _Utility App - Utility App
2022-05-31T06:42:42.3632226Z ==============================================================================
2022-05-31T06:42:42.3632956Z Task         : Download build artifacts
2022-05-31T06:42:42.3633439Z Description  : Download files that were saved as artifacts of a completed build
2022-05-31T06:42:42.3633715Z Version      : 0.200.1
2022-05-31T06:42:42.3634068Z Author       : Microsoft Corporation
2022-05-31T06:42:42.3634549Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/download-build-artifacts
2022-05-31T06:42:42.3634953Z ==============================================================================
2022-05-31T06:42:49.0078464Z Error: in getBuild, so retrying => retries pending  : 4
2022-05-31T06:43:34.1171511Z Error: in getBuild, so retrying => retries pending  : 3
2022-05-31T06:45:49.4315894Z Error: in getBuild, so retrying => retries pending  : 2
2022-05-31T06:51:49.7774413Z Error: in getBuild, so retrying => retries pending  : 1
2022-05-31T06:57:49.9960407Z ##[error]Failed in getBuild with error: Error: VS800075: The project with id 'vstfs:///Classification/TeamProject/{GUID}' does not exist, or you do not have permission to access it.
2022-05-31T06:57:50.0533271Z ##[error]Error: VS800075: The project with id 'vstfs:///Classification/TeamProject/{GUID}' does not exist, or you do not have permission to access it.
2022-05-31T06:57:50.0572339Z ##[section]Finishing: Download artifact - _Utility App - Utility App

I couldn’t find a clear answer for how to fix it but managed to get there with some trial and error!

Continue reading “Allowing Azure DevOps Release Pipelines Access to Remote Artifacts”

Null Reference Exception in Blazor Router

A screenshot of a stack trace produced from a .NET application. The main messages are "An unhandled exception occurred while processing the request. NullReferenceException: Object reference not set to an instance of an object. Microsoft.AspNetCore.Components.Routing.Router.Refresh(bool isNavigationIntercepted)". A full stack trace is visible below.

If you’ve used Blazor for a while you may have run into the following (pretty unhelpful) error message where the page router is throwing a NullReferenceException:

A screenshot of a stack trace produced from a .NET application. The main messages are "An unhandled exception occurred while processing the request. NullReferenceException: Object reference not set to an instance of an object. Microsoft.AspNetCore.Components.Routing.Router.Refresh(bool isNavigationIntercepted)". A full stack trace is visible below.
But what am I trying to reference that is null?!

The worst part is that I always seem to run into this error after making a bunch of changes and then having no idea exactly what I did to break the build (yeah I know, I should probably run my code more while making changes).

I’ve managed to form a general idea of why the error is thrown and have found two concrete situations that reproducibly cause the issue, so I’ve finally written them down for when I inevitably run into this situation again!

Continue reading “Null Reference Exception in Blazor Router”

Applying Authorisation Rules to a Folder of Razor Components/Blazor Pages

A screenshot of a Blazor app designed to test/demonstrate different approaches to applying authorisation rules to razor components

There’s a lot of flexibility in how you can use authorisation rules in Razor components*, but a frustration of this approach is that it seems like you have to slap @attribute [Authorize(Policy = "PolicyName")] at the top or every page with no clear way of applying a given policy to a whole folder of .razor files. After much research and testing, I’ve found how to go about it!

Continue reading “Applying Authorisation Rules to a Folder of Razor Components/Blazor Pages”

Calling .NET Instance Methods in ASP.NET Core Blazor Directly from JavaScript

A header image depicting an arrow pointing from the JavaScript logo to the Blazor logo

I ran into an issue recently where I needed to call some C# code from JavaScript. The Microsoft documentation on JavaScript to .NET interop is very detailed and covers a lot of scenarios including the one that would seem to fit the bill (invoking instance methods), but my requirements meant that I couldn’t use this exact approach.

Continue reading “Calling .NET Instance Methods in ASP.NET Core Blazor Directly from JavaScript”

UI Flashes after Migrating Blazor Projects To .NET 6

A table with the title of "Vegetables". There are three columns (Id, Product and Quantity) and 3 rows of example data.

The Problem

I’ve noticed an issue recently after upgrading a few Blazor projects from .NET 5 to .NET 6 where the UI flashes after every call to StateHasChanged. Something like this:

A table with the title of "Vegetables". There are three columns (Id, Product and Quantity) and 3 rows of example data. The Id field disappears and reappears once a second causing the table to visibily shift back and forth
Flash. Flash. Flash. Flash…

Yeah, that’s not annoying at all. Unfortunately it was happening in quite a few different places and was pretty darn noticeable, so it looked like I was going to have to dive in and figure out what exactly was causing this to go wrong (despite working perfectly in .NET 5)!

Continue reading “UI Flashes after Migrating Blazor Projects To .NET 6”

Referencing Blazorise Theme Values in Custom CSS

A header image displaying two different div elements with two differently coloured shadows

Introduction

Blazorise is an excellent library that I’ve been using a lot lately. While it has great support for declaring custom visual themes, you’ll occasionally run into situations where what you’re trying to do isn’t fully supported.

Take this super contrived example: I want to set the shadow on a div to use the primary colour defined in my theme, but there’s no attribute in Blazorise to do this directly (at time of writing). I could hard-code the colour to the same hex value as what I’ve set in my theme, but not only is this generally bad practice (since it’s easy to update one value and not the other), it locks you into only one colour even though the theme can be modified dynamically during runtime. So how can we access our Blazorise theme values in custom CSS?

Continue reading “Referencing Blazorise Theme Values in Custom CSS”