Blazor Error - There is no Registered Service of Type

Expirementing with Blazor, I ran into this error showing up in the console: "There is no regisered 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 expirementing & 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

I am a Software Developer primarily using JavaScript and C#. I write about Building Software, Web Security and Artificial Intelligence. Besides tech, I occasionally write about fitness, education & business.

comment

Comments