elringus / bootsharp

Compile C# solution into single-file ES module with auto-generated JavaScript bindings and type definitions

Home Page:https://bootsharp.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How does the bootData section work for web?

DanielHabenicht opened this issue · comments

Hi,
I tried implementing the bootData section for your example project:

    // Providing implementation for 'GetHostName' function declared in 'HelloWorld' C# assembly.
    dotnet.HelloWorld.GetHostName = () => "Browser";

    async function loadfile(path) {
        response = await fetch(path);
        // Examine the text in the response
        buffer = await response.arrayBuffer();
        return Base64.fromUint8Array(new Uint8Array(buffer));
    }

    window.onload = async function () {
        allfiles = [
            "Microsoft.JSInterop.WebAssembly.dll",
            "System.Collections.Concurrent.dll",
            "System.Private.Runtime.InteropServices.JavaScript.dll",
            "System.Collections.dll",
            "Microsoft.AspNetCore.Components.Web.dll",
            "System.Memory.dll",
            "Microsoft.JSInterop.dll",
            "Microsoft.AspNetCore.Components.WebAssembly.dll",
            "System.Runtime.dll",
            "System.Text.Json.dll",
            "Microsoft.AspNetCore.Components.dll",
            "System.Private.Uri.dll",
            "System.Private.CoreLib.dll",
            "System.Runtime.CompilerServices.Unsafe.dll",
            "System.Console.dll",
            "DotNetJS.dll",
            "System.Text.Encodings.Web.dll",
            "HelloWorld.dll",
        ];
        assemblies = [];
        for (let i = 0; i < allfiles.length; i++) {
            assemblies.push({
                name: allfiles[i],
                data: await loadfile("Project/bin/Debug/net6.0/" + allfiles[i]),
            });
        }
        // Booting the DotNet runtime and invoking entry point.
        const bootData = {
            wasm: await loadfile("Project/bin/Debug/net6.0/dotnet.wasm"),
            assemblies: assemblies,
            entryAssemblyName: "HelloWorld.dll",
        };
        await dotnet.boot(bootData);
        // Invoking 'GetName()' C# method defined in 'HelloWorld' assembly.
        const guestName = dotnet.HelloWorld.GetName();
        console.log(`Welcome, ${guestName}! Enjoy your global space.`);
    };

But I always get this error, any idea why?

dotnet.js:488 Uncaught (in promise) RuntimeError: abort(TypeError: WebAssembly.instantiate(): Import #0 module="a" error: module is not an object or function). Build with -s ASSERTIONS=1 for more info.
    at abort (dotnet.js:488:25)
    at dotnet.js:542:25

Remark:
I also tried the Project/bin/Debug/net6.0/publish/wwwroot/_framework/ Path.

In your case it's probably failing because you're using dotnet.wasm from the .NET SDK, which is not supported at the moment due to #20

That was lightning fast!
Thanks, yes it was.
I was already looking at the test but failed to notice the native/ path.