Skip to content

DryIoc is not working together with Blazor InputFile component #690

@RexTremendae

Description

@RexTremendae

I spent quite some time trying to figure out why I couldn't get the <InputFile> component to work with my Blazor Server web app, until I did a git bisect and ended up with the commit that introduced DryIoc. With this finding, I could recreate a minimal reproduction of the problem.

Using .net SDK 10.0.100-rc.2.25502.107 on Windows 11, I performed the following steps:

  1. Create a new template app using the dotnet CLI:
    dotnet new blazor

  2. On the Counter.razor page (or any other page, but it is important that the @rendermode InteractiveServer directive is specified on top of the page), add the following code:

<InputFile OnChange=OnChange />

@code {

    private async Task OnChange(InputFileChangeEventArgs e)
    {
        var file = e.GetMultipleFiles()[0];
        await using var stream = file.OpenReadStream();
        var content = new byte[100];
        await stream.ReadExactlyAsync(content, 0, 100);

        Console.WriteLine("Reading from stream finished!");
    }
}

Running this example at this state works fine, uploading a file will output the success message on the console.

  1. Add nuget DryIoc.Microsoft.DependencyInjection of version 8.0.0-preview-04
  2. Modify the top lines of Program.cs:
using DryIoc;
using DryIoc.Microsoft.DependencyInjection;

var builder = WebApplication.CreateBuilder(args); // This line comes from the template

var container = new Container(DryIocAdapter.MicrosoftDependencyInjectionRules);
var diFactory = new DryIocServiceProviderFactory(container, RegistrySharing.Share);

builder.Host.UseServiceProviderFactory(diFactory);

// the rest of the template code goes here...

Now, uploading a file with this modified code simply does not work. Nothing happens, no console output. After a while a timeout occurs:

fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
      Unhandled exception in circuit 'kcOgJKCKqIWG12sqEUR93dymC91etiaDJbrwGyJi4j4'.
      System.TimeoutException: Did not receive any data in the allotted time.
         at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result)
         at System.IO.Pipelines.Pipe.GetReadAsyncResult()
         at System.IO.Pipelines.PipeReaderStream.ReadAsyncInternal(Memory`1 buffer, CancellationToken cancellationToken)

This means that it is not currently possible to use DryIoc if I also want to use the <InputFile> component, so I have to chose one or the other.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions