Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSInterop Exception in Published Blazor WebAssembly App (Server Mode) #58454

Closed
1 task done
hwmbing11 opened this issue Oct 16, 2024 · 3 comments
Closed
1 task done
Assignees
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved

Comments

@hwmbing11
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Description: When running a Blazor WebAssembly application in server mode in debug and release modes, everything works fine. However, when the application is published, it throws a Microsoft.JSInterop.JSException with the following error message:

blazor.web.js:1 Uncaught (in promise) Error: Microsoft.JSInterop.JSException: An exception occurred executing JS interop: ConstructorContainsNullParameterNames, System.Lazy`1[System.Threading.Tasks.Task`1[Microsoft.JSInterop.IJSObjectReference]]. See InnerException for more details.
 ---> System.NotSupportedException: ConstructorContainsNullParameterNames, System.Lazy`1[System.Threading.Tasks.Task`1[Microsoft.JSInterop.IJSObjectReference]]
   at System.Text.Json.ThrowHelper.ThrowNotSupportedException_ConstructorContainsNullParameterNames(Type )
   at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.PopulateParameterInfoValues(JsonTypeInfo )
   at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.CreateTypeInfoCore(Type , JsonConverter , JsonSerializerOptions )
   at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.CreateJsonTypeInfo(Type , JsonSerializerOptions )
   at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetTypeInfo(Type , JsonSerializerOptions )
   at System.Text.Json.JsonSerializerOptions.GetTypeInfoNoCaching(Type )
   at System.Text.Json.JsonSerializerOptions.CachingContext.CreateCacheEntry(Type type, CachingContext context)
--- End of stack trace from previous location ---
   at System.Text.Json.JsonSerializerOptions.CachingContext.CacheEntry.GetResult()
   at System.Text.Json.JsonSerializerOptions.CachingContext.GetOrAddTypeInfo(Type , Boolean )
   at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type , Boolean , Nullable`1 , Boolean , Boolean )
   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo.Configure()
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.ConfigureProperties()
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure()
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureSynchronized|172_0()
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.EnsureConfigured()
   at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type , Boolean , Nullable`1 , Boolean , Boolean )
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure()
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureSynchronized|172_0()
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo.EnsureConfigured()
   at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type , Boolean , Nullable`1 , Boolean , Boolean )
   at System.Text.Json.JsonSerializerOptions.GetTypeInfoForRootType(Type , Boolean )
   at System.Text.Json.JsonSerializer.GetTypeInfo(JsonSerializerOptions , Type )
   at System.Text.Json.JsonSerializer.Deserialize(Utf8JsonReader& , Type , JsonSerializerOptions )
   at Microsoft.JSInterop.JSRuntime.EndInvokeJS(Int64 , Boolean , Utf8JsonReader& )
   Exception_EndOfInnerExceptionStack
   at BlazorApp2.Client.BlazorBlob.BlobStreamService.GetBrowserFilesAsync(ElementReference inputFileElement, CancellationToken cancellationToken)
   at BlazorApp2.Client.Pages.TestDir.OnFileSelected(InputFileChangeEventArgs e)
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
    at y.endInvokeDotNetFromJS (https://localhost:7015/_framework/blazor.web.js:1:3502)
    at Object.ri [as endInvokeDotNetFromJS] (https://localhost:7015/_framework/blazor.web.js:1:165319)
    at https://localhost:7015/_framework/dotnet.runtime.8.0.8.h5wrorseig.js:3:178428
    at Ll (https://localhost:7015/_framework/dotnet.runtime.8.0.8.h5wrorseig.js:3:179262)
    at wasm://wasm/00b21c96:wasm-function[349]:0x1f99d
    at wasm://wasm/00b21c96:wasm-function[245]:0x1be41
    at wasm://wasm/00b21c96:wasm-function[238]:0xf00e
    at wasm://wasm/00b21c96:wasm-function[306]:0x1e693
    at wasm://wasm/00b21c96:wasm-function[327]:0x1ee89
    at wasm://wasm/00b21c96:wasm-function[217]:0xce5e

Repository:
BlazorTest

Expected Behavior

he published application throws a Microsoft.JSInterop.JSException with the error message mentioned above.

Steps To Reproduce

  1. To clone the repository mentioned above, you can use the following command:
git clone https://github.com/hwmbing11/BlazorTest.git
  1. Run the application in debug and release modes to ensure it works correctly.
  2. Publish the application using the following command:
dotnet publish -c Release -r linux-x64 -o ~/publish
  1. Start the published application using the following command:
cd ~/publish && dotnet BlazorApp2.dll --urls "https://localhost:7015"
  1. Run the published application and observe the error.

Exceptions (if any)

No response

.NET Version

8.0.402

Anything else?

dotnet --info:

.NET SDK:
 Version:           8.0.402
 Commit:            70aa751718
 Workload version:  8.0.400-manifests.b6724b7a
 MSBuild version:   17.11.4+37eb419ad

Runtime Environment:
 OS Name:     debian
 OS Version:  12
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /usr/share/dotnet/sdk/8.0.402/

Host:
  Version:      8.0.8
  Architecture: x64
  Commit:       08338fcaa5

.NET SDKs installed:
  8.0.402 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.8 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.8 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

IDE: Rider

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Oct 16, 2024
@danroth27
Copy link
Member

We think this might be a linking issue where content is being removed that causes JSON serialization to get impacted, but we need to investigate.

@halter73
Copy link
Member

halter73 commented Oct 16, 2024

The problem seems to be that System.Text.Json (S.T.J) does not know how to deserialize the Lazy<Task<IJSObjectReference>> LazyFileTask. Before you publish, S.T.J able to inspect Lazy<T>, determine it's not deserializable, and skip over the property. But after publishing and trimming, S.T.J does not have enough metadata about Lazy<T> to determine if it's deserializable or not and errors out.

You can add [JsonIgnore] to LazyFileTask to tell S.T.J to always skip over it without checking if it's deserializable and get rid of the JS interop exception.

@halter73 halter73 added the ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. label Oct 16, 2024
Copy link
Contributor

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved
Projects
None yet
Development

No branches or pull requests

3 participants