Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

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

$
0
0

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


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>