SfDialogService error

Hi, I am having problems to use  SfDialogService component in a .net 6.0 and Blazor Server project.

I followed the link below to add the necessary code but keep getting System.NullReferenceException: 'Object reference not set to an instance of an object.'  when it is called. 

Please help, thanks

Peter

-----


Class SfDialogService - Blazor API Reference | Syncfusion


in program.cs, I added these lines

    using Syncfusion.Blazor;

    using Syncfusion.Blazor.Popups;

...

    builder.Services.AddScoped<SfDialogService>();

   builder.Services.AddSyncfusionBlazor(options => { options.IgnoreScriptIsolation = true; });

..


in razor file, I added these

@using Syncfusion.Blazor

@using Syncfusion.Blazor.Popups;

@inject SfDialogService DialogService

<button class="btn btn-primary" @onclick="Alert">Alert Modal</button>

@code {

    private async Task Alert()

    {

        //await DialogService.AlertAsync(message);

        await DialogService.PromptAsync("Prompt Dialog Content");

    }

}




4 Replies

BS Buvana Sathasivam Syncfusion Team August 8, 2022 05:12 PM UTC

Hi Peter,


Greetings from Syncfusion support.


Please follow the below steps to render a predefined dialog using the register dialog service.

Step #1: Register the Syncfusion Blazor SfDialogService in the Program.cs file.

using Syncfusion.Blazor;

using Syncfusion.Blazor.Popups;

 

builder.Services.AddScoped<SfDialogService>();

builder.Services.AddSyncfusionBlazor();


Step #2: Add the SfDialogProvider component in the MainLayout.razor file.


MainLayout.razor

<main>

        <article class="content px-4">

            @Body

             <Syncfusion.Blazor.Popups.SfDialogProvider />

        </article>

    </main>


Step #3: Use the following code to render the predefined Dialog as an application.


@using Syncfusion.Blazor.Popups

@inject SfDialogService DialogService

    <div>

        <button class="e-btn dlgbtn" @onclick="@AlertBtn">Alert</button>

        <button class="e-btn dlgbtn" @onclick="@ConfirmBtn">Confirm</button>

        <button class="e-btn dlgbtn" @onclick="@PromptBtn">Prompt</button>

    </div>

@code {

    private async Task AlertBtn()

    {

        await DialogService.AlertAsync("10% of battery remaining", "Low Battery");

    }

    private async Task ConfirmBtn()

    {

        bool isConfirm = await DialogService.ConfirmAsync("Are you sure you want to permanently delete these items?", "Delete Multiple Items");

    }

    private async Task PromptBtn()

    {

        string promptText = await DialogService.PromptAsync(null, "Join Wi-Fi network", new DialogOptions()

        {

            ChildContent = @<table class="Table">

                    <tbody>

                        <tr>

                            <td>SSID:</td>

                        </tr>

                    </tbody>

                </table>

        });

    }

}

 


Please find the below sample for your reference.

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Net6Server_-_Copy_(2)_-_Copy-87269210


Release Notes: https://blazor.syncfusion.com/documentation/release-notes/20.2.36?type=all#dialog

If you still have a problem, can you please share your Syncfusion package version and share the issue reproducible sample?

Regards,

Buvana S



TA Takuya September 17, 2022 01:56 AM UTC

This phenomenon is reproduced in package version 20.2.0.49.


The initial value of the title of ConfirmAsync, AlertAsync, and PromptAsync of SfDialogService is null, but NullReferenceException will occur if it is executed as null.


await DialogService.ConfirmAsync("content");          // NullReferenceException
await DialogService.ConfirmAsync("content", "title"); // No Problem


VJ Vinitha Jeyakumar Syncfusion Team September 19, 2022 01:04 PM UTC

Hi Takuya,


We have considered your reported issue "Throwing null reference exception when passing null values for dialog title in SfDialogService" as a bug from our end and the fix for the issue will be included with our upcoming Vol 3 Main release which is expected to be rolled out on the end of September 2022.

Now you can track the status of the reported issue through the below feedback,

Regards,
Vinitha


VJ Vinitha Jeyakumar Syncfusion Team September 30, 2022 11:54 AM UTC

Hi Takuya,

 

We are glad to announce that our Essential Studio 2022 Volume 3 release v20.3.0.47 is rolled out and is available for download under the following link.

 

https://www.syncfusion.com/forums/177858/essential-studio-2022-volume-3-main-release-v20-3-0-47-is-available-for-download

 

We have also included the fix for the issue "Throwing null reference exception when passing null values for dialog title in SfDialogService" with our Vol 3 Main release version 20.3.47. So please upgrade your package to the latest to resolve the issue from your end.


Release Notes: https://blazor.syncfusion.com/documentation/release-notes/20.3.47?type=all#dialog


We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you require any further assistance.

 

Regards,          

Vinitha

Loader.
Up arrow icon