Skip to content

TokenizedTextBox throws "NamedResource Not Found. (0x80073B17)" upon load with AppSDK preview 3 #4355

Open
@gus33000

Description

@gus33000

Describe the bug

Upon loading a TokenizedTextBox control in an App SDK packaged or unpackaged project, when using localized properties, the following exception is thrown:
image

  • Is this bug a regression in the toolkit? If so, what toolkit version did you last see it work: 7.1.1 (UWP)

Steps to Reproduce

  • Can this be reproduced in the Sample App? (Either in a sample as-is or with new XAML pasted in the editor.) If so, please provide custom XAML or steps to reproduce. If not, let us know why it can't be reproduced (e.g. more complex setup, environment, dependencies, etc...)

No sample app is available for App SDK preview 3 as far as I'm aware so I cannot test it here.

Steps to reproduce the behavior:

  1. Create a new AppSDK preview 3 packaged project with WinUI 3
  2. Add a reference to the CommunityToolkit 7.1.1-preview3
  3. Add the following xaml in mainwindow.xaml:
<Window
    x:Class="App1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App1"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:ctk="using:CommunityToolkit.WinUI.UI.Controls"
    mc:Ignorable="d">

    <ctk:TokenizingTextBox Margin="0,4"
                           CornerRadius="8"
                           ItemsSource="{x:Bind TestCollection, Mode=TwoWay}"
                           PlaceholderText="{local:ResourceString Name=TestPlaceholder}"
                           TokenDelimiter=";" />
</Window>
  1. Add the following code in mainwindow.xaml.cs
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Markup;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Microsoft.Windows.ApplicationModel.Resources;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace App1
{
    public static class ResourceStringHelper
    {
        /// <summary>
        /// Gets the following resource string from the application resx files
        /// This method cannot be called from any thread.
        /// </summary>
        /// <param name="id">The identifier of the resource string</param>
        /// <returns></returns>
        public static string GetStringFromResources(string id)
        {
            ResourceLoader resourceLoader = new ResourceLoader();
            return resourceLoader.GetString(id);
        }
    }

    [MarkupExtensionReturnType(ReturnType = typeof(string))]
    public sealed class ResourceString : MarkupExtension
    {
        public string Name
        {
            get; set;
        }

        protected override object ProvideValue()
        {
            return ResourceStringHelper.GetStringFromResources(Name);
        }
    }

    /// <summary>
    /// An empty window that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainWindow : Window
    {
        public ObservableCollection<string> TestCollection = new();

        public MainWindow()
        {
            this.InitializeComponent();
        }
    }
}
  1. Add a new Resources.resw, in Strings\en\Resources.resw, with a single key/value pair: "TestPlaceholder" => "I'm a test"
  2. In configuration manager, tick the deploy checkbox so visual studio deploys the application
  3. Run the application
  4. An exception is thrown

Expected behavior

The control should load and work properly without an exception being thrown.

Environment

NuGet Package(s):

  • CommunityToolkit.WinUI.UI.Controls
  • Microsoft.WindowsAppSDK (1.0.0-preview3)
  • Microsoft.Windows.SDK.BuildTools (10.0.20348.19)

Package Version(s):

7.1.1-preview3

Windows 10 Build Number:

  • Fall Creators Update (16299)
  • April 2018 Update (17134)
  • October 2018 Update (17763)
  • May 2019 Update (18362)
  • May 2020 Update (19041)
  • Insider Build (22000.282)

App min and target version:

  • Fall Creators Update (16299)
  • April 2018 Update (17134)
  • October 2018 Update (17763)
  • May 2019 Update (18362)
  • May 2020 Update (19041)

Device form factor:

  • Desktop
  • Xbox
  • Surface Hub
  • IoT

Visual Studio version:

  • 2022 (17.Preview/17.0.0-pre.7.0+31825.309)

Additional context

The control works fine without the localized string, removing it makes it work. However the issue is not the local:ResourceString markup extension as using it in a textblock works fine, as such:

<Window
    x:Class="App1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App1"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:ctk="using:CommunityToolkit.WinUI.UI.Controls"
    mc:Ignorable="d">

    <TextBlock Text="{local:ResourceString Name=TestPlaceholder}"/>
</Window>

Metadata

Metadata

Assignees

No one assigned

    Labels

    WinUI 💠Related to WinUI 3 Version or when paired with External can mean requires fix in WinUI 2/3.bug 🐛An unexpected issue that highlights incorrect behaviorcontrols 🎛️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions