Skip to content

ApplicationData.GetForUnpackaged() API spec - #6946

Open
Howard Kapustein (DrusTheAxe) wants to merge 3 commits into
mainfrom
user/drustheaxe/6934-ApplicationData.GetForUnpackaged-apispec
Open

Howard Kapustein (DrusTheAxe) wants to merge 3 commits into
mainfrom
user/drustheaxe/6934-ApplicationData.GetForUnpackaged-apispec

Conversation

@DrusTheAxe

@DrusTheAxe Howard Kapustein (DrusTheAxe) commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

API Spec for Feature Request: ApplicationData.GetForUnpackaged() overload that gives unpackaged apps a way to declare its default ApplicationData #6934

API spec for issue #6934

@DrusTheAxe Howard Kapustein (DrusTheAxe) added this to the 3.0 milestone Nov 5, 2026
@DrusTheAxe Howard Kapustein (DrusTheAxe) added the area-ApplicationData Topics related to ApplicationData APIs in the Microsoft.Windows.Storage namespace label Nov 5, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@DrusTheAxe Howard Kapustein (DrusTheAxe) changed the title ApplicationData.GetForUnpackaged() ApplicationData.GetForUnpackaged() API spec Nov 6, 2026
`ApplicationData.GetForUnpackaged(publisher, product)` e.g. they must be strings
with length >0.

`SetContextForUnpackaged()` fails if the context has already been set i.e. calling

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The presence of a SetContextFor... implies a GetContextFor... so a caller can know if it's already been set.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1.

Scenario 1: I want to set the unpackaged identity if I am running unpackaged and the unpackaged identity hasn't already been set. (Say because I set things up so the main guy can set the identity if it wants, and if not, I'll fall back to a default one.) How do I know whether it is safe to call SetContextForUnpackaged()? Does GetForUnpackaged() return null?

Scenario 2: I want to know whether the unpackaged identity has been set so I know ahead of time whether it is safe to call GetForUnpackaged().

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol yeah, I'd mentioned that to Jesse but left it as a wait-and-see option. Seen enough :-)

And good examples Raymond

Adding GetContextForUnpackaged()

}
return std::wstring{ reinterpret_cast<PCWSTR>(::LockResource(resourceValue)) };
}
```

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, you defined all these helpers but never defined the algorithm for GetForUnpackaged itself.

#2 is needed by components used in processes where the component author doesn't know the calling
processes' context at build time, and isn't otherwise able to be handed the context at runtime. The
application sets the context fo the process and component authors use whatever has been defined for
the process' context.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if I'm a component that wants to be usable in both packaged and unpackaged processes. How do I know whether to use AppplicationData.GetDefault().LocalPath or ApplicationData.GetForUnpackaged().LocalPath?

Right now, GetDefault() throws an exception if called from an unpackaged app.

Or are we going to modify GetDefault() so it forwards to GetForUnpackaged() if called from an unpackaged app?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking this further: do we even need the new parameterless GetForUnpackaged()? Can we just use GetDefault()?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keith> GetDefault() works off the process' package identity. Adding 'context' support to that would complicate matters (regardless if we say context trumps identity or vice versa). I don't see that as a helpful step forward.

Raymond> The APIs are distinct worlds, so the decision tree is simple

if (IsPackagedProcess())
    appdata = ApplicationData.GetDefault()
else
    appdata = ApplicationData.GetForUnpackaged()

Or you could always try one and fallback to the other, but since WinRT throws exceptions when not-set (and there's no TryGet...) that could be more painful than desirable.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsPackagedProcess() isn't that trivial to define in C++ or especially C# in the most performant way, though. And to the end user, both unpackaged and packaged ApplicationData objects behave the same, so they don't have to check whether the process is packaged afterwards either.

So I would also +1 for making GetDefault() work for unpackaged apps

`ApplicationData.GetForUnpackaged(publisher, product)` e.g. they must be strings
with length >0.

`SetContextForUnpackaged()` fails if the context has already been set i.e. calling

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1.

Scenario 1: I want to set the unpackaged identity if I am running unpackaged and the unpackaged identity hasn't already been set. (Say because I set things up so the main guy can set the identity if it wants, and if not, I'll fall back to a default one.) How do I know whether it is safe to call SetContextForUnpackaged()? Does GetForUnpackaged() return null?

Scenario 2: I want to know whether the unpackaged identity has been set so I know ahead of time whether it is safe to call GetForUnpackaged().


#2 is needed by components used in processes where the component author doesn't know the calling
processes' context at build time, and isn't otherwise able to be handed the context at runtime. The
application sets the context fo the process and component authors use whatever has been defined for

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo

`ApplicationData.GetForUnpackaged(publisher, product)` e.g. they must be strings
with length >0.

`SetContextForUnpackaged()` fails if the context has already been set i.e. calling

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make things more convenient to the app author if SetContextForUnpackaged failed only if there is an attempt to set the context to something different to the previous call. Otherwise the app author is forced to keep track of whether they have already set it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Good idea - Set to current value should succeed.

Goal was to not allow changing it once set. Set(x,y) Nx doesn't violate that so it should be allowed.


## 4.6. Component in Unpackaged app using LocalPath - Context defined at build-time

A component in an unpackaged app app creating a file in the app's LocalPath data store when the app

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app app

nit: typo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-ApplicationData Topics related to ApplicationData APIs in the Microsoft.Windows.Storage namespace

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants