2

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

Jason Pan
  • 15,263
  • 1
  • 14
  • 29
  • Does this answer your question? [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – TheTanic Jul 10 '23 at 07:19
  • Please provide code samples that re-create the problem, not screenshots. – Mister Magoo Jul 10 '23 at 08:29

1 Answers1

1

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);
        }
    }
}
Jason Pan
  • 15,263
  • 1
  • 14
  • 29
  • The solution is still not working. – PriyankaKarthikeyan Jul 11 '23 at 11:32
  • @PriyankaKarthikeyan Could you share more error details? – Jason Pan Jul 11 '23 at 12:21
  • The above solution handled the null exception, but I am facing an issue with running this sample. https://uploadnow.io/f/cy8kJSy – PriyankaKarthikeyan Jul 12 '23 at 12:43
  • 1
    Hi @PriyankaKarthikeyan, you are facing stackoverflowExceptions, right ? The names of your model and razor page are both `Test`, which encounters an ambiguity at runtime, please modify the name to solve the problem. – Jason Pan Jul 14 '23 at 07:31
  • Hi @PriyankaKarthikeyan If my reply is helpful, please accept it as answer(click on the mark option beside the reply to toggle it from greyed out to fill in.), see https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – Jason Pan Jul 14 '23 at 07:32