abpframework / abp

Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
https://abp.io
GNU Lesser General Public License v3.0
12.88k stars 3.44k forks source link

An exception occurs when using JSRuntime.InvokeAsync<byte[]>("readByteArray") in BlazorServer. #17160

Closed haoxj0823 closed 9 months ago

haoxj0823 commented 1 year ago

Is there an existing issue for this?

Description

When using JSRuntime.InvokeAsync<byte[]>("readByteArray") in BlazorServer, the following exception occurs:

Microsoft.JSInterop.JSException: An exception occurred executing JS interop: JSON serialization is attempting to deserialize an unexpected byte array.. See InnerException for more details.
---> System.Text.Json.JsonException: JSON serialization is attempting to deserialize an unexpected byte array.
at Microsoft.JSInterop.Infrastructure.ByteArrayJsonConverter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.Serialization.JsonConverter`1.ReadCoreAsObject(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.JsonSerializer.ReadCore[TValue](Utf8JsonReader& reader, JsonTypeInfo jsonTypeInfo, ReadStack& state)
at System.Text.Json.JsonSerializer.Read[TValue](Utf8JsonReader& reader, JsonTypeInfo jsonTypeInfo)
at Microsoft.JSInterop.JSRuntime.EndInvokeJS(Int64 taskId, Boolean succeeded, Utf8JsonReader& jsonReader)
--- End of inner exception stack trace ---
at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args)

In TargetFramework 7.0 and ABP 7.3.0, it is an exception, in TargetFramework 6.0 and ABP 6.0.3, it is normal, but in TargetFramework 7.0 and ABP 6.0.3, it is an exception.

The BlazorServer template provided by ABP also has the same problem. I used the BlazorServer template provided by dotnet and used ABP in the smallest way, only referencing the Volo.Abp.Autofac package, and the problem is the same.

TestProject URL https://github.com/haoxj0823/BlazorServerTestProject

Reproduction Steps

No response

Expected behavior

No response

Actual behavior

No response

Regression?

No response

Known Workarounds

No response

Version

7.3.0

User Interface

Blazor Server

Database Provider

None/Others

Tiered or separate authentication server

None (Default)

Operation System

Windows (Default)

Other information

No response

maliming commented 1 year ago

hi

How about without abp?

haoxj0823 commented 1 year ago

hi

How about without abp?

When the code related to ABP is commented out, it can work correctly.

using BlazorServerTestProject;
using BlazorServerTestProject.Data;
using Volo.Abp;

var builder = WebApplication.CreateBuilder(args);

// Abp
// builder.Host.UseAutofac();
// builder.Services.AddApplication<BlazorServerModule>();

// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddSingleton<WeatherForecastService>();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

app.UseHttpsRedirection();

app.UseStaticFiles();

app.UseRouting();

app.MapBlazorHub();
app.MapFallbackToPage("/_Host");

app.Run();

TestProject URL https://github.com/haoxj0823/BlazorServerTestProject

maliming commented 1 year ago

Your test code gets 404 error first.

GET https://localhost:7258/pages/index.razor.js net::ERR_ABORTED 404 (Not Found)