最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论