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");
        }
    }

Matt Ferderer

Full Stack Software Developer focused on JavaScript and C#. Love to share & help others make amazing things. Have a project you need help on? Let's talk!

comment

Comments