0
votes

When I run a UWP app in Debug mode, ApplicationData exists.

When I run in Release mode, it seems ApplicationData has gone out of scope. Rather, accessing it times out.

I've added two lines to a stock UWP Blank page app solution:

sealed partial class App : Application
{
    /// <summary>
    /// Initializes the singleton application object.  This is the first line of authored code
    /// executed, and as such is the logical equivalent of main() or WinMain().
    /// </summary>
    public App()
    {
        this.InitializeComponent();
        string strPath = 
            Windows.Storage.ApplicationData.Current.LocalFolder.Path; // <<< Added
        System.Diagnostics.Debug.WriteLine(strPath);    // <<< Added
        this.Suspending += OnSuspending;
    }
//...

Running in debug mode, ApplicationData.Current.LocalFolder.Path exists, and strPath is something like...

C:\Users\AUser\AppData\Local\Packages\[some guid-like number]_7442be4pe7dnc\LocalState

Running in Release mode, if I check up on things in the Immediate Window, I get this...

ApplicationData.Current.LocalFolder.Path,nq
The name 'ApplicationData' does not exist in the current context

And hovering over the code itself gives me a strange timeout:

enter image description here

If ApplicationData isn't in scope in a release app, how do I get to the folder? If it is supposed to be in scope, why wouldn't it be here?


EDIT: Same thing happens when I try to access ApplicationData in a click event for a button, so it's not a timing/initialization thing.

1

1 Answers

2
votes

When I run in Release mode, it seems ApplicationData has gone out of scope. Rather, accessing it times out.

When running your UWP application in release mode. VS build your codes using .Net Native Tool Chain and also optimize the codes by default. And it is not a suitable environment for debugging. But it won't change the output of your codes. You just can't see it in debugger.

You can disable building with .Net Native Tool Chain and codes optimization by following steps:

right click your project file->Properties->Build tag on left-> uncheck Compile with .Net Native tool chain and uncheck Optimize code like below: enter image description here

And now you can debug your codes in release mode correctly.