canhorn / EventHorizon.Blazor.TypeScript.Interop.Generator

This project is a Blazor Interop C# Generator, has a sample against the BabylonJS library.
https://wonderful-pond-05f7b3b10.azurestaticapps.net/
MIT License
132 stars 19 forks source link

Error: Canvas GetElementById returns null in WASM .NET Core 6 #63

Closed bdizzleog closed 2 years ago

bdizzleog commented 2 years ago

Hello,

I've ran into an issue when I was using this generator in a Blazor Server project and it worked fine, but in production it would lag for the client so I decided to switch my project to webassembly and use the generator for that instead.

Everything seemed to have gone too smoothly, which it did, when I start my project 'Canvas.GetElementById' returns null. This has been very frustrating as I haven't been able to figure it out for days now.

It is difficult to debug because right when it goes into the method it returns null immediately. image

And right when I step into the return: 'Object reference not set to an instance of an object.'

I'm not sure what this could be, I tried to copy Canvas.cs from the sample projects but it didn't make a difference.

bdizzleog commented 2 years ago

I tried breaking down GetElementById but it actually seems that it's not erroring in this method. image

It seems as though it is erroring in 'EventHorizonBlazorInterop.FuncClass(x,x,x)'

Nuget shows the latest version 0.2.5 image

bdizzleog commented 2 years ago

I added EventHorizon.Blazor.Interop to my project so I could debug.

It looks like 'RUNTIME' returns null.

image

bdizzleog commented 2 years ago

This whole time it was my own fault for missing 1 part of the setup.

I was missing in App.razor:

@code {
    [Inject]
    public IJSRuntime JSRuntime { get; set; }

    protected override void OnInitialized()
    {
        EventHorizonBlazorInterop.JSRuntime = JSRuntime;
    }
}