Forum Discussion

Auri_Rahimzadeh's avatar
Auri_Rahimzadeh
Copper Contributor
Jan 17, 2025
Solved

Module object available in .NET 6 Blazor WASM Project, but not in .NET 8+ After Upgrade

I have a working project in .NET 6 that calls the following JS code:

export function synchronizeFileWithIndexedDb(filename) {
    return new Promise((res, rej) => {
        const db = window.indexedDB.open('SqliteStorage', 1);
        db.onupgradeneeded = () => {
            db.result.createObjectStore('Files', { keypath: 'id' });
        };

        db.onsuccess = () => {
            const req = db.result.transaction('Files', 'readonly').objectStore('Files').get('file');
            req.onsuccess = () => {
                Module.FS_createDataFile('/', filename, req.result, true, true, true);
                res();
            };
        };
    });
}
 

And behind the scenes in OnInitializedAsync:

    if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("browser")))
    {
      // create SQLite database file in browser
      var module = await _js.InvokeAsync<IJSObjectReference>("import", "./dbstorage.js");
      await module.InvokeVoidAsync("synchronizeFileWithIndexedDb", SqliteDbFilename);
    }

This works perfectly in .NET 6, which is unfortunately now EOL.

Simply upgrading it to .NET 8 causes "Module" (see line 11) to no longer be defined. I ran into the same problem using a brand new .NET 9 project as well. If it's .NET 6 it works, .NET 8 or higher it breaks.

Is this a known issue? I'm afraid of upgrading anything with JS Interop now πŸ˜›

Is there a path forward? I tried changing Module to DotNet, based on reading MSFT docs, but that didn't work. I don't want to go back to .NET 6 to solve this if I don't have to :)

You can try it yourself simply by upgrading the following Sqlite WASM project:

https://github.com/TrevorDArcyEvans/BlazorSQLiteWasm

 

  • AHH, finally found the solution. Breaking change in .NET 9 (though I had the same issue in .NET 8). 

    https://learn.microsoft.com/en-us/dotnet/core/compatibility/aspnet-core/9.0/legacy-apis

    Module can be changed to Blazor.runtime to solve.

1 Reply

  • Auri_Rahimzadeh's avatar
    Auri_Rahimzadeh
    Copper Contributor

    AHH, finally found the solution. Breaking change in .NET 9 (though I had the same issue in .NET 8). 

    https://learn.microsoft.com/en-us/dotnet/core/compatibility/aspnet-core/9.0/legacy-apis

    Module can be changed to Blazor.runtime to solve.

Resources