Skip to content
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

[Bug] BlazoredToast.OnInitializedAsync null reference exception in 4.2.0 #251

Closed
rramer-web-com opened this issue Feb 23, 2024 · 2 comments · Fixed by #255
Closed

[Bug] BlazoredToast.OnInitializedAsync null reference exception in 4.2.0 #251

rramer-web-com opened this issue Feb 23, 2024 · 2 comments · Fixed by #255
Labels
Bug Something isn't working

Comments

@rramer-web-com
Copy link

In 4.2.0, Settings.ShowProgressBar is null in BlazoredToast.OnInitializedAsync when using a ToastService.ShowToast method without explicitly providing optional settings that override ShowProgressBar.

ex. _toastService.ShowToast<Alert>(toastParameters);

This leads to the following runtime error:

Error: System.InvalidOperationException: Nullable object must have a value.
   at System.Nullable`1.get_Value()
   at Blazored.Toast.BlazoredToast.OnInitializedAsync()
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()

It looks like the breaking changes were in the following commit which changed ShowProgressBar from bool to bool?

Fix settings to allow instance settings to override global settings (https://github.com/Blazored/Toast/pull/226[)](https://github.com/Blazored/Toast/commit/1f0f1d839ea0177798f6712aff29646fbbacc78a)

BlazoredToasts.BuildCustomToastSettings(Action? settings) might need to define a sensible default.

@rramer-web-com rramer-web-com added Bug Something isn't working Triage Issue needs to be triaged labels Feb 23, 2024
@gracefaz
Copy link
Contributor

We have been able to recreate this in the repo by using the ShowToast<TComponent> method where ToastSettings is not a parameter. This method sets ToastSettings to null which resulted in ShowProgressBar also being null. According to this line, ShowProgressBar cannot be null.

PR with a proposed fix here: #255

@chrissainty chrissainty removed the Triage Issue needs to be triaged label Mar 19, 2024
@hovek
Copy link

hovek commented Aug 23, 2024

Version is 4.2.1 and I have the issue: NullReferenceException: Object reference not set to an instance of an object.
Blazored.Toast.BlazoredToast.OnInitializedAsync()

I just have <BlazoredToast /> in MainLayout.razor on the client and it throws on app startup in the browser.
If we need to provide ToastSettings it is very inconvenient because it requires a bunch of arguments provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants