I am using IndexedDB in a Blazor WASM app. When the app starts up, it invokes a JS function that does a GetAll() against one of the database stores and returns the result. The problem occurs in a published version of the app (Release mode) when the database store is empty. I haven't tried it in the debugger because I'm reluctant to clear my debugging database.
I log console message before and after the C# statement that invokes JS as well as in the JS itself. The logging shows the IndexedDB request comes back in "onsuccess" with a result.length of 0. But the C# console log statement following the one that invokes JSRuntime doesn't execute, suggesting that the JSRuntime is having a problem assigning the 0 length result to the MyObjects array (maybe a Json deserialization problem). Any idea what I'm missing or how to get around the problem?
Console.WriteLine("c# #1: Invoke JS GetAll");
MyObjects[] myObjectsArray = await MES.JSRuntime.InvokeAsync<MyObjects[]>("MyJS_GetAll");
Console.WriteLine("c# #2: Return from JS GetAll");
function MyJS_GetAll ()
{
return new Promise(function (resolve, reject)
{
let req = myDatabase.transaction(myStoreName, "readwrite")
.objectStore(myStoreName)
.getAll();
req.onsuccess = function (event)
{
console.log("SUCCESS");
resolve(req.result);
}
req.onerror = function (event)
{
console.log("ERROR");
reject('ERROR \n ' + (event.target as any).errorCode);
}
});
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744189814a4562380.html
评论列表(0条)