Search code examples
.net-coreblazorwebassemblyblazor-client-side

Native error in .NET Core Blazor WebAssembly


My task is to run a CLI command (in the client's system) and to show the output to the user on the Web app. [assume, a web-based cmd.exe]

Based on reading about WebAssembly's capabilities, I used the .NET CORE Blazor WebAssembly to do the task. But using the System.Diagnostics.ProcessStartInfo in Client throws runtime error Native error= Cannot find the specified file.

Please let me know if my understanding of WebAssembly is wrong. Also, suggest how I could accomplish the task?

Code used in Razor page:

protected override async Task OnInitializedAsync()
{
    quiz = await Http.GetJsonAsync<List<QuizItem>>("Quiz");

    // My actual code...
    string process = @"C:\Windows\System32\cmd.exe", arguments = "start", workingFolder = ".";
    System.Diagnostics.ProcessStartInfo startinfo = new System.Diagnostics.ProcessStartInfo {
        FileName = process, Arguments = arguments, WorkingDirectory = workingFolder,
        CreateNoWindow = false, UseShellExecute = false,
        RedirectStandardError = true, RedirectStandardOutput = true,
    };
    System.Diagnostics.Process proc = System.Diagnostics.Process.Start (startinfo);
    if (proc == null) throw new Exception ($"Unable to execute '{process}'");
}

Console log for reference:

enter image description here


Solution

  • The permissions of blazor are limited by the browser javascript sandbox, so you cannot do anything you also cannot do in javascript. Starting processes is one of them.