SamProf/MatBlazor

FileUpload component stops program

Nergy101 opened this issue · 1 comments

Hi there,

I am running into a problem when uploading one or multiple files through the upload component.
It keeps stopping my App/Program as soon as I upload something. Debugger or not makes no difference.

The program '[207068] iisexpress.exe' has exited with code -1 (0xffffffff).

So AFAIK there's no errors, also not in the web-console.

Used packages/csproj info:

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Blazm.Bluetooth" Version="0.0.2" />
    <PackageReference Include="MatBlazor" Version="2.8.0" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.6" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.6" PrivateAssets="all" />
    <PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
    <PackageReference Include="Toolbelt.Blazor.HotKeys" Version="10.0.1" />
  </ItemGroup>

I am using the file upload like so:

<MatFileUpload AllowMultiple="true" OnChange="@(files => FilesReadyForContent(files, note))"></MatFileUpload>

with FilesReadyForContent being:

 private async Task FilesReadyForContent(IMatFileUploadEntry[] files, Note note)
    {
        foreach (var file in files)
        {
            using (var stream = new System.IO.MemoryStream())
            {
                await file.WriteToStreamAsync(stream);

                note.Attachments.Add(new Attachment
                {
                    UploadedBy = CreatorName,
                    OriginalFileName = file.Name,
                    ServerFileName = Guid.NewGuid(),
                    FileContent = stream.ToArray()
                });
            }
        }

        StateHasChanged();
    }

It will work, it will add them to this "Note" I am editing, show the files' information, etc.
Somehow the literal Server app stops running as soon as I upload a file though.

Anyone have an idea why this is happening?

Turns out the stream.ToArray() breaks Blazor somehow.

Just using MemoryStream now instead works fine 👍