Blazor Error - There is no Registered Service of Type

Experimenting with Blazor, I ran into this error showing up in the console: "There is no registered service of type..." Fortunately there is a simple fix. In my case, I added a class & injected into a Razor view. What I forgot to do, was add it as a service in Program.cs. In my case, my well named class was named Stuff because I was truly experimenting & naming things is hard.

By injecting a service to my Program.cs, the error went away & my program executed without any issues.

    public class Program
    {
        static void Main(string[] args)
        {
            var serviceProvider = new BrowserServiceProvider(services =>
            {
                services.AddSingleton<Stuff>();
            });

            new BrowserRenderer(serviceProvider).AddComponent<App>("app");
        }
    }

One Last Thing...

If you have a question or see a mistake, please comment below.

If you found this post helpful, please share it with others. It's the best thanks I can ask for & it gives me momentum to keep writing!

Matt Ferderer
Software Developer focused on making great user experiences. I enjoy learning, sharing & helping others make amazing things.
Let's Connect