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

How does the bootData section work for web? #48

Closed
DanielHabenicht opened this issue Apr 21, 2022 · 3 comments
Closed

How does the bootData section work for web? #48

DanielHabenicht opened this issue Apr 21, 2022 · 3 comments

Comments

@DanielHabenicht
Copy link

DanielHabenicht commented Apr 21, 2022

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.

@elringus
Copy link
Owner

Hi, Check this from the test suite: https://github.com/Elringus/DotNetJS/blob/cad9a87854fd860203d25991a55bb3a68fa11229/JavaScript/dotnet-runtime/test/csharp.js#L18 It creates the boot data for the test cs project.

@elringus
Copy link
Owner

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

@DanielHabenicht
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants