Blazor NET8 localStorage getItem gives IJSRuntime error or disconnects from server
I am updating a Blazor hosted web app from net6 to a Blazor Web App in net8, and have been unable to retrieve an item from local storage. I can successfully SET the item in localStorage, and after I set it, I want to retrieve it. But on GET item I get the IJSInProcessRuntime not available error (in other variations of my code I become disconnected from the server). A similar stackoverflow question included this response: ” you can just use the OnAfterRender hook and use StateHasChanged ” , which I thought I was doing: since the IJS runtime is not available until after the page has rendered, my GetItem is now in the OnAfterRenderAsync method, and I am using StateHasChanged once I have set my GetImageBool trigger to true to get the item. I have tried different rendermodes, with and without prerendering, and get the same error. Per the Microsoft docs, I’ve moved my “SET” javascript (which works) to MyAssemblyName.lib.module.js. I tried a workaround to have eventArgsCreator also return the item instead of only saving it in localstorage, however, an async method is required to to create the saved value (“thisimage” is a Base64string), and the app crashes on load when I set eventArgsCreator to be an async function (to await the call to funcLocal). Program.cs correctly contains builder.Services.AddBlazoredLocalStorage(); What am I missing?
Blazor NET8 localStorage getItem gives IJSRuntime error or disconnects from server
I am updating a Blazor hosted web app from net6 to a Blazor Web App in net8, and have been unable to retrieve an item from local storage. I can successfully SET the item in localStorage, and after I set it, I want to retrieve it. But on GET item I get the IJSInProcessRuntime not available error (in other variations of my code I become disconnected from the server). A similar stackoverflow question included this response: ” you can just use the OnAfterRender hook and use StateHasChanged ” , which I thought I was doing: since the IJS runtime is not available until after the page has rendered, my GetItem is now in the OnAfterRenderAsync method, and I am using StateHasChanged once I have set my GetImageBool trigger to true to get the item. I have tried different rendermodes, with and without prerendering, and get the same error. Per the Microsoft docs, I’ve moved my “SET” javascript (which works) to MyAssemblyName.lib.module.js. I tried a workaround to have eventArgsCreator also return the item instead of only saving it in localstorage, however, an async method is required to to create the saved value (“thisimage” is a Base64string), and the app crashes on load when I set eventArgsCreator to be an async function (to await the call to funcLocal). Program.cs correctly contains builder.Services.AddBlazoredLocalStorage(); What am I missing?