Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

129
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda