New to Telerik UI for BlazorStart a free 30-day trial

DialogFactory is Null

Environment

Product Dialog for Blazor,
RootComponent for Blazor

Description

The following exception may occur when calling the AlertAsync(), ConfirmAsync(), or PromptAsync() methods of the Telerik Blazor DialogFactory:

System.NullReferenceException: Object reference not set to an instance of an object

The following exception may occur on initial page load:

InvalidOperationException: Cannot provide a value for property '...' on type '...'. There is no registered service of type 'Telerik.Blazor.DialogFactory'

Cause

The null reference exception occurs if the DialogFactory CascadingParameter was not populated by the TelerikRootComponent. This in turn indicates one of the following:

  • The TelerikRootComponent is missing in the Blazor app.
  • The root component is present, but it's in the same .razor file as the DialogFactory cascading parameter.
  • The Blazor app is using Per Page / Component Interactity Location and the root component is present, but it's in a static .razor component or layout.

The invalid operation exception occurs if the app tries to inject the DialogFactory as a dependency injection (service), which is not the intended way to use the predefined Telerik dialogs.

Solution

The following technical requirements ensure correct DialogFactory setup:

See Also