-
Notifications
You must be signed in to change notification settings - Fork 80
kb(Dialog): Add KB for null DialogFactory #2671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| --- | ||
| title: DialogFactory is Null | ||
| description: How to troubleshoot, fix and resolve a System.NullReferenceException Object reference not set to an instance of an object, which occurs when the TelerikRootComponent or the Telerik Blazor DialogFactory for predefined dialogs are not setup correctly. | ||
| type: troubleshooting | ||
| page_title: Telerik Blazor DialogFactory is Null | ||
| slug: dialog-kb-dialogfactory-null | ||
| tags: telerik, blazor, dialog, dialogfactory | ||
| ticketid: 1674088, 1673922, 1661511 | ||
| res_type: kb | ||
| --- | ||
|
|
||
| ## Environment | ||
|
|
||
| <table> | ||
| <tbody> | ||
| <tr> | ||
| <td>Product</td> | ||
| <td> | ||
| Dialog for Blazor, <br /> | ||
| RootComponent for Blazor | ||
| </td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
|
|
||
| ## Description | ||
|
|
||
| The following exception may occur when calling the `AlertAsync()`, `ConfirmAsync()`, or `PromptAsync()` methods of the [Telerik Blazor `DialogFactory`]({%slug dialog-predefined%}): | ||
|
|
||
| `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`]({%slug dialog-predefined%}#telerikrootcomponent-dependency). This in turn indicates one of the following: | ||
|
|
||
| * The [`TelerikRootComponent`]({%slug rootcomponent-overview%}) 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 <a href="https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-modes?view=aspnetcore-9.0#apply-a-render-mode-to-a-component-definition" target="_blank">**Per Page / Component** Interactity Location</a> 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: | ||
|
|
||
| * [Place a `TelerikRootComponent` in a layout `.razor` file]({%slug rootcomponent-overview%}#using-telerikrootcomponent) in the app when using the application types below. If the `DialogFactory` must be avalable in the layout file itself, then [place the `TelerikRootComponent` in a parent layout file]({%slug getting-started/what-you-need%}#optimal-telerikrootcomponent-usage). | ||
| * [Blazor Web App]({%slug getting-started/web-app%}) with <a href="https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-modes?view=aspnetcore-9.0#apply-a-render-mode-to-the-entire-app" target="_blank">**Global** Interactivity Location</a>. | ||
| * [WebAssembly standalone app]({%slug getting-started/client-side%}) | ||
| * [Blazor Hybrid app]({%slug getting-started/hybrid-blazor%}) | ||
| * When using a Blazor Web App with <a href="https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-modes?view=aspnetcore-9.0#apply-a-render-mode-to-a-component-definition" target="_blank">**Per Page / Component** Interactity Location</a>, [place the `TelerikRootComponent` inside an interactive Razor component]({%slug rootcomponent-percomponent%}), which is a parent of the component that consumes the `DialogFactory`. | ||
| * Always [consume the `DialogFactory` as a `[CascadingParameter]`]({%slug dialog-predefined%}), and not as a dependency injection with `@inject`. | ||
|
|
||
| ## See Also | ||
|
|
||
| * [Predefined Blazor Dialogs]({%slug dialog-predefined%}) | ||
| * [TelerikRootComponent Overview]({%slug rootcomponent-overview%}) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purpose of this nested list is unclear. The ending punctuation for the list items is inconsistent.