dadhi / DryIoc

DryIoc is fast, small, full-featured IoC Container for .NET
MIT License
988 stars 122 forks source link

Blazor File Upload issue with Net 7 and MS DI Package #547

Closed oruchreis closed 1 year ago

oruchreis commented 1 year ago

Hi, I don't know it is relevant or not with #544 but If we use DryIoc.Microsoft.DependencyInjection v6.*.* package with Net 7, the file upload doesn't work. I'm integrating DryIoc like this: Program.cs:

var builder = WebApplication.CreateBuilder(args);
builder.Host.UseServiceProviderFactory(new DryIocServiceProviderFactory());

and simple upload page: Upload.razor:

<InputFile OnChange="Upload" />
@_newDocumentUploadProgress %
@code {
    private double _newDocumentUploadProgress;
    private async Task Upload(InputFileChangeEventArgs args)
    {
        var file = args.File;
        await using var uploadStream = file.OpenReadStream(maxAllowedSize: 10 * 1024 * 1024);
        var bytesRead = 0;
        var totalRead = 0;
        var buffer = new byte[10];
        await using var memStream = new MemoryStream();

        while ((bytesRead = await uploadStream.ReadAsync(buffer)) != 0)
        {
            totalRead += bytesRead;

            await memStream.WriteAsync(buffer, 0, bytesRead);

            _newDocumentUploadProgress = (totalRead / uploadStream.Length) * 100;
            StateHasChanged();
        }

        memStream.Position = 0;
    }
}

Actually all js streaming is not working with DryIoc.Microsoft.DependencyInjection v6.* with Net 7. If I comment out DryIocServiceProviderFactory line, it is working.

dadhi commented 1 year ago

@oruchreis Huh, more incencitive to release #544 faster. Thanks.

MaxwellDAssistek commented 1 year ago

I can reproduce this issue as well and it does not happen without DryIoc. Here is the actual exception that is happening:

2023-04-14 09:36:46.604 -04:00 [VRB] InvocationId null: Sending result of type 'System.Void'.
2023-04-14 09:36:46.605 -04:00 [DBG] Parameters to hub method 'ReceiveJSDataChunk' are incorrect.
System.IO.InvalidDataException: Invocation provides 4 argument(s) but target expects 3.
   at Microsoft.AspNetCore.SignalR.Protocol.MessagePackHubProtocolWorker.BindArguments(MessagePackReader& reader, IReadOnlyList`1 parameterTypes)
   at Microsoft.AspNetCore.SignalR.Protocol.MessagePackHubProtocolWorker.CreateInvocationMessage(MessagePackReader& reader, IInvocationBinder binder, Int32 itemCount)
2023-04-14 09:36:46.634 -04:00 [DBG] Parameters to hub method 'ReceiveJSDataChunk' are incorrect.
System.IO.InvalidDataException: Invocation provides 4 argument(s) but target expects 3.
   at Microsoft.AspNetCore.SignalR.Protocol.MessagePackHubProtocolWorker.BindArguments(MessagePackReader& reader, IReadOnlyList`1 parameterTypes)
   at Microsoft.AspNetCore.SignalR.Protocol.MessagePackHubProtocolWorker.CreateInvocationMessage(MessagePackReader& reader, IInvocationBinder binder, Int32 itemCount)
2023-04-14 09:36:52.641 -04:00 [VRB] Message received. Type: "Binary", size: 3, EndOfMessage: true.
dadhi commented 1 year ago

@oruchreis @MaxwellDAssistek I have checked that it is working with .NET 7 and DryIoc.MS.DI v6.2.0-preview-01

Maxwell175 commented 1 year ago

@dadhi Can confirm that it works for me as well.