Action Delegate Throws NullReferenceException On Invoke

Viewed 91

Here I have a Blazor server app, where I call C# method TransferFileName from Js function. The TransferFileName gets the value in parameter fileName as expected, but the problem is that there is NullReferenceException in DownloadFileNameAction.Invoke(fileName); line.

This is my code:

public static Action<string> DownloadFileNameAction;

[JSInvokable]
public static void TransferFileName(string fileName)
{
    DownloadFileNameAction.Invoke(fileName);
}

protected override async Task OnInitializedAsync()
{
    DownloadFileNameAction = TransferFileToUserForDownload;
}

public async void TransferFileToUserForDownload(string fileName)
{
   var getFileName = fileName;
   // code omitted
}
0 Answers
Related