Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
Blazor WebbAssembly exception when calling javascript function?

I have a C# function that is invoking a Javascript function, this is the C# function:

await _jsRuntime.InvokeVoidAsync("setMediaUsingStreaming", type, dotnetImageStream);

And this is the Javascript function:

   async function setMediaUsingStreaming(fileType, fileStream) {
            try {

                const arrayBuffer = await fileStream.arrayBuffer();
                const blob = new Blob([arrayBuffer]);
                const url = URL.createObjectURL(blob);

                var newHTMLElement;
                var fileHTMLElement = document.getElementById('fileDisplay');

                if (fileType == "image") {
                    newHTMLElement = document.createElement('img');
                }
                else {
                    newHTMLElement = document.createElement('video');
                    var attribute = document.createAttribute('controls');
                    newHTMLElement.setAttributeNode(attribute);
                }

                fileHTMLElement.appendChild(newHTMLElement);
                newHTMLElement.src = url;

            } catch (Exception)
            {
                console.log(Exception)
            }
   } 

When the C# function is invoking the Javascript function I receive this error :

blazor.webassembly.js:1 Uncaught (in promise) Error: Microsoft.JSInterop.JSException: Cannot set properties of null (setting 'src') TypeError: Cannot set properties of null (setting 'src')

The weird thing is that I receive this error when I run the app in publish mode (withouth a debugger) but it works perfectly in debug mode. The catch from the javascript function is not hit when I receive this error, it seems that is the C# method that is throwing it.

I know what the error is saying, that the url variable is null, but I don't understand why is null, and why it works on debug mode.

Do you have any ideas ?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!