‘__generated__Index.OnInitAsync()’: no suitable method found to override

Reading Time: 2 minutes.

Welp – just ran into this one, and as I expect others to encounter the same issue, better document in right away!

So in Blazor, I was crafting a simple component that’d display some data in a nice way. Being lazy and crafty, I thought I’d copy-paste some similar code from an earlier POC I had built, since I knew it worked. The component was overriding a method called “OnInitAsync”, and it just nicely fetched data after initialized.

But alas, it didn’t. Not anymore. I got the following error:

Error    CS0115  '__generated__Index.OnInitAsync()': no suitable method found to override ...

The code I was copying was for a simple component was just retrieving some info from a background service, and it worked in the other project. But critically, the other project was built on an earlier version of .NET Core 3.0

This was actually due to Microsoft updating the .NET Core 3.0 (to preview 8) and the Razor component classes’ default methods – and changing their names. They themselves describe the relevant change like this:

In Razor components rename OnInit to OnInitialized and OnInitAsync to OnInitializedAsync.

So, in short, if you as well are now using .NET Core 3.0 preview 8 or later, and you were copypasting your code from anything before that, you need to change your overridden methods in a following manner:

  • OnInit needs to change to OnInitialized
  • OnInitAsync needs to change to OnInitializedAsync

And after that, you should be good!

You can read the whole list of changes here. That’s it – quick and clean! 😊

Antti K. Koskela

Antti Koskela is a proud digital native nomadic millennial full stack developer (is that enough funny buzzwords? That's definitely enough funny buzzwords!), who works as a Solutions Architect for Valo Intranet, the product that will make you fall in love with your intranet. Working with the global partner network, he's responsible for the success of Valo deployments happening all around the world.

He's been a developer from 2004 (starting with PHP and Java), and he's been bending and twisting SharePoint into different shapes since MOSS. Nowadays he's not only working on SharePoint, but also on .NET projects, Azure, Office 365 and a lot of other stuff.

This is his personal professional (e.g. professional, but definitely personal) blog.

Leave a Reply

Notify of