unoplatform/uno · error · NotSupportedException

Unsupported ms-appx target

Error message

Unsupported ms-appx target

What it means

Thrown by the SVG image source sample when copying an ms-appx asset into an application-data folder whose name is not one of 'Local', 'Temp', or 'Roaming'. The switch expression has no arm for other names, so the default throws NotSupportedException.

Source

Thrown at src/SamplesApp/SamplesApp.Samples/Windows_UI_Xaml_Controls/ImageTests/SvgImageSource_FromMsAppData.xaml.cs:123

	{
		try
		{
			if (ImageElement.Source is not SvgImageSource svgImageSource)
			{
				svgImageSource = new SvgImageSource();
				ImageElement.Source = svgImageSource;
			}

			if (SelectedSource != null)
			{
				var file = await StorageFile.GetFileFromApplicationUriAsync(SelectedSource.Uri);

				var targetFolder = SelectedSource.Name switch
				{
					"Local" => ApplicationData.Current.LocalFolder,
					"Temp" => ApplicationData.Current.TemporaryFolder,
					"Roaming" => ApplicationData.Current.RoamingFolder,
					_ => throw new NotSupportedException("Unsupported ms-appx target")
				};

				await file.CopyAsync(targetFolder, file.Name, NameCollisionOption.ReplaceExisting);

				svgImageSource.UriSource = new Uri($"ms-appdata:///local/{file.Name}");

				var text = await FileIO.ReadTextAsync(file);
				using MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(text));
				await svgImageSource.SetSourceAsync(stream.AsRandomAccessStream());
			}

			if (Enum.TryParse(SelectedStretch, out Stretch stretch))
			{
				ImageElement.Stretch = stretch;
			}

			if (double.TryParse(ImageWidth, out var width))
			{

View on GitHub (pinned to 0418340488)

Solutions

  1. Add a switch arm for the new folder name mapping to ApplicationData.Current.LocalCacheFolder (or the appropriate folder).
  2. Ensure SelectedSource.Name is exactly cased 'Local'/'Temp'/'Roaming'.
  3. If the new target is not an ApplicationData folder, handle it explicitly rather than relying on the default arm.

Example fix

// before
var targetFolder = SelectedSource.Name switch
{
    "Local" => ApplicationData.Current.LocalFolder,
    "Temp" => ApplicationData.Current.TemporaryFolder,
    "Roaming" => ApplicationData.Current.RoamingFolder,
    _ => throw new NotSupportedException("Unsupported ms-appx target")
};
// after
var targetFolder = SelectedSource.Name switch
{
    "Local" => ApplicationData.Current.LocalFolder,
    "LocalCache" => ApplicationData.Current.LocalCacheFolder,
    "Temp" => ApplicationData.Current.TemporaryFolder,
    "Roaming" => ApplicationData.Current.RoamingFolder,
    var n => throw new NotSupportedException($"Unsupported ms-appx target: '{n}'")
};
Defensive patterns

Strategy: validation

Validate before calling

static readonly HashSet<string> KnownFolders = new(){"Local","LocalCache","Temp","Roaming"};
if (!KnownFolders.Contains(SelectedSource.Name)) throw new NotSupportedException($"Unsupported ms-appx target: {SelectedSource.Name}");

Prevention

When it happens

Trigger: SelectedSource.Name returns something other than the three known folder keys — e.g. a new entry added to the source list without a matching switch arm, a localized or renamed folder name, or a null/different casing.

Common situations: Extending the sample with a new StorageFolder target (e.g. 'LocalCache', 'SharedLocal') and forgetting the switch arm; case mismatch ('local' vs 'Local'); the data model gaining a new enum value.

Related errors


AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13). Data as JSON: /api/errors/388992b89e9d0010. Report an issue: GitHub.