steam3d
steam3d

Reputation: 197

Windows Storage Error with Windows Application Packaging Project

I have Blank UWP project packed to Windows Application Packaging Project.

Both projects have:

enter image description here

I wrote a simple code in App.xaml.cs to create setting value

using Windows.Storage;
...
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
    ApplicationDataContainer Sett = ApplicationData.Current.LocalSettings;
    if (Sett.Values["test"] == null)
        {
            Sett.Values["test"] = true;
        }
    // Sett.Values["test"] = true; // Also causes an error
    ...
}

When i run TestPkg (x86 debug) i got this message in debug console

onecoreuap\base\appmodel\statemanager\winrt\lib\windows.storage.applicationdatafactory.server.cpp(235)\Windows.Storage.ApplicationData.dll!7B6D1391: (caller: 05769996) ReturnHr(1) tid(546c) 8000000B The operation attempted to access data outside the valid range
Msg:[User XXX]

Value saved correctly i can read it without problem. The error only occurs if you pack UWP to Windows Application Packaging Project.

I also tried this with windows.fullTrustProcess (UWP + WPF) on both In both cases, the behavior is similar.

How can i fix this? Source: https://github.com/steam3d/Windows.Storage.Error

Upvotes: 2

Views: 1436

Answers (3)

sjb-sjb
sjb-sjb

Reputation: 1187

I had a similar error using WinUI 3 Preview 3 with a desktop app packaged in MSIX.

In my case the exception occurred some time during launch. I do have code in there that accesses Windows.Storage.ApplicationData.

The exception I see in my debugger is copied below with a source code line.

onecoreuap\base\appmodel\statemanager\winrt\lib\windows.storage.applicationdatafactory.server.cpp(235)\Windows.Storage.ApplicationData.dll!16891391: (caller: 0E7F9FB1) ReturnHr(1) tid(33bc) 8000000B The operation attempted to access data outside the valid range Msg:[User S-1-5-21-3122765350-3099923779-1351685958-1002] Exception thrown at 0x7679A892 (KernelBase.dll) in Q5U.exe: 0x40080202: WinRT transform error (parameters: 0x8000000B, 0x80070490, 0x00000014, 0x005BE3F4). OnLaunched (Kind=Launch)

Upvotes: 0

Dan Scavezze
Dan Scavezze

Reputation: 43

I also see this error. I’m using VS 2019. Here are some more data points about the problem. Maybe they will provide a clue.

  1. I kept commenting out my app initialization code and eventually found that the one statement var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; would generate the error “The operation attempted to access data outside the valid range”

  2. After my app is initialized, I use the statement above before writing to the localSettings. In that case, I get a different error “There are no more endpoints available from the endpoint mapper.”

  3. It seems to be real time related. In one use case of my app, I issue the statement above every 5 seconds. In that case, I get the error “There are no more endpoints...” at total seconds of 5, 15, 25, etc. but not at total seconds of 10, 20, 30, etc. If I put a breakpoint at the statement, and slow things down, then I get the error every time as in 5, 10, 15, 20, 25, etc.

Upvotes: 0

LDS
LDS

Reputation: 362

Check the bellow code may solved

ApplicationDataContainer Sett = ApplicationData.Current.LocalSettings;
var value = Sett.Values["#Test"];
 
if (value == null)
{
   Sett.Values["#Test"] = 5;
}

Upvotes: -4

Related Questions