DryIoc is not working together with Blazor InputFile component
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:
-
Create a new template app using the dotnet CLI:
dotnet new blazor -
On the
Counter.razorpage (or any other page, but it is important that the@rendermode InteractiveServerdirective 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.
- Add nuget
DryIoc.Microsoft.DependencyInjectionof version8.0.0-preview-04 - 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.
Thanks for the steps. I will check.