PriyankaKarthikeyan
PriyankaKarthikeyan

Reputation: 23

SignalR causing null reference exception while adding custom dialog services

We are trying to add custom services with SignalR, but it throws a null exception when we invoke the custom services. If we specify the component tag in mainLayout.razor like <BlazorApp3.DialogForms.Test/>, it is unable to run the project.

Sample: https://uploadnow.io/f/Y59l8d9

enter image description here enter image description here

enter image description here enter image description here

Are we missing any configuration in the attached sample?

Need to run the signalR with custom dialog service sample without any exception

Upvotes: 2

Views: 202

Answers (1)

Jason Pan
Jason Pan

Reputation: 21873

Change your DialogService class like below and the issue could be fixed.

using System;
using Microsoft.AspNetCore.Components;

namespace BlazorApp3.DialogForms
{
    public class DialogService
    {
        private event Action<DialogOptions> dialogInstance;

        public event Action<DialogOptions> DialogInstance
        {
            add => dialogInstance += value;
            remove => dialogInstance -= value;
        }
        public async Task Open(DialogOptions options)
        {
            // Invoke Test to update and show the dialog with options
            this.dialogInstance?.Invoke(options);
        }
    }
}

Upvotes: 1

Related Questions