.Net Core 6 JavaScript Replace missing for Byte Array

franks_00001 1 Reputation point

I've upgrade a Blazor 3.1 solution to Core 6. I've worked out all the issues, except 1.
EPPlus uses Byte Array when creating Excel extracts. However after .Net Core 6 upgrade the Replace function for Byte Array can't be found "sBase64.replace is not a function". I'm guess 5.0 and earlier had an override or something for Byte Array that allowed Replace to be used.

I have tried to do the upgrade from scratch, 1 piece at a time. Core 5 worked fine; but as soon as I upgrade to 6 it started failing again.

Yes, I tried changing the Byte Array to String, it gets through the JavaScript error; but the XLSX file created by EPPlus can't be opened in Excel.

Was JavaScript Byte Array Replace part of .Net Core, and will it be coming back in 6?
Is there a workaround?

Using the latest...

<PackageReference Include="EPPlus" Version="6.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Negotiate" Version="6.0.7" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.7" />
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.22.0" />

A set of technologies in the .NET Framework for building web applications and XML web services.
4,133 questions
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,373 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Michael Taylor 47,626 Reputation points

    I'm not aware of any Replace function for ByteArray in any version of .NET. You mention EPPlus, byte arrays, strings and Javascript so it is confusing as to exactly what Replace function you're talking about. Please go back to your working code and right click the Replace function and go to definition on it. Please identify where this function is coming from and what the signature (as far as the compiler is concerned) is.

  2. Bruce (SqlWork.com) 54,711 Reputation points

    .net core has no impact on javascript functions. they are defined by javascript, or by javascript script files.

    javascript has a string.replace()

    javascript does not have a byte datatype. it does have ArrayBuffers which supports a typed array (its binary and the typed defines unit buffer size).

    var buffer = new Int8Array(32); // 32 byte binary array

    typed arrays just like normal arrays do not have a .replace() method

    note: blazor js interop uses json, which does not support binary data. typically you would convert to a base64 string to expose via json.

    0 comments No comments

  3. Bruce (SqlWork.com) 54,711 Reputation points

    once enough details were added to the question. the answer is simple:

    the javascript code example was written for blazor 5.0, and a .net byte array was passed via js interop. in blazor 5.0 byte array were passed a base64 string to the javascript tfunction. In blazor 6, a breaking change was made to pass byte array to javascript as Uint8Array (typed binary array).

    as the function is expecting a base64 string, in blazor the byte array should be converted to a base64 string before calling the function.

    you could also update the javascript function to accept a Uint8Array, and change the base64 decode logic.

    0 comments No comments