Skip to content

Possible regression in JavaScript [JSImport]/[JSExport] interop in a Blazor app (.NET 8 Preview 5) #87690

@guardrex

Description

@guardrex

Description

Pavel, I'm working on doc updates for the Webcil (.wasm) .NET assembly packing format for .NET 8 preview docs.

One of the JS import/export examples calls getAssemblyExports on the app's assembly, so I was checking that example. While doing so, I noticed an error when running the example in a Pre5 test app.

The section is located at ...

https://learn.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/import-export-interop?view=aspnetcore-7.0#call-net-from-javascript

When the component is accessed, it works as described ...

image

When that error is checked, it appears as ...

blazor.webassembly.js:1 Error: Assert failed: ES6 module CallDotNet1 was not imported yet, please call JSHost.ImportAsync() first.

JSHost.ImportAsync() is called (and ultimately works) ...

protected override async Task OnInitializedAsync()
{
    await JSHost.ImportAsync("CallDotNet1",
        "../Pages/CallDotNet1.razor.js");
}

Cross-reference: https://github.com/guardrex/BlazorWASM80Pre5WebcilCheck/blob/main/Pages/CallDotNet1.razor#L16-L17

Reproduction Steps

I put up a sample app with that example ...

https://github.com/guardrex/BlazorWASM80Pre5WebcilCheck

Expected behavior

No module load error in the console.

Actual behavior

image

Regression?

AFAIK, there was no error when we put the guidance up.

Known Workarounds

None

Configuration

  • .NET 8 Preview 5
  • Windows 11 Pro
  • x64
  • Don't know if it's specific to this config.
  • MS Edge Version 114.0.1823.43 (Official build) (64-bit)

Other information

None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions