Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

125
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda