maui: x:Array as resource with key crashes app on device launch

Description

This works in the iOS simulator and on desktop. The goal is to have an array of data I can reuse by key.

<?xml version="1.0" encoding="UTF-8" ?>
<?xaml-comp compile="true" ?>
<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">

    <x:Array Type="{x:Type x:String}" x:Key="CategoriesArray">
        <x:String>Noodles</x:String>
        <x:String>Rice</x:String>
        <x:String>Appetizers</x:String>
        <x:String>Desserts</x:String>
        <x:String>Beverages</x:String>
    </x:Array>

</ResourceDictionary>

This initially was in the Styles.xaml which I split apart for troubleshooting and used merged dictionaries.

That doesn’t work on an iOS device. I get an error about the type converter failing.

The below however does work on the ContentPages:

<BindableLayout.ItemsSource>
    <x:Array Type="{x:Type x:String}" >
        <x:String>Noodles</x:String>
        <x:String>Rice</x:String>
        <x:String>Appetizers</x:String>
        <x:String>Desserts</x:String>
        <x:String>Beverages</x:String>
    </x:Array>
</BindableLayout.ItemsSource>

Steps to Reproduce

Add an array with key to your styles, bind to a BindableLayout, and then run on an iOS device.

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 15

Did you find any workaround?

don’t use a resource

Relevant log output

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 18 (13 by maintainers)

Commits related to this issue

Most upvoted comments

Hi,

The issue happens also when we publish Android app with AOT enable.

Regards.

I can also attest that this issue is still happening. On a blank MAUI template project, adding x:String entries to the Styles.xaml resource dictionary causes the app to crash when it is deployed to a device (iOS and Android). Interestingly, it only occurs when <MtouchLink> is set to SdkOnly in the csproj file. If it is set to None, the problem goes away.

This is a serious blocker to a project I am working on.

My workload version are as follows:

Installed Workload Id      Manifest Version       Installation Source
---------------------------------------------------------------------
wasm-tools                 7.0.2/7.0.100          SDK 7.0.100        
macos                      13.1.1007/7.0.100      SDK 7.0.100        
maui-maccatalyst           7.0.59/7.0.100         SDK 7.0.100        
maui-ios                   7.0.59/7.0.100         SDK 7.0.100        
maui-android               7.0.59/7.0.100         SDK 7.0.100        
ios                        16.2.1007/7.0.100      SDK 7.0.100        
maccatalyst                16.2.1007/7.0.100      SDK 7.0.100        
maui                       7.0.59/7.0.100         SDK 7.0.100        
android                    33.0.26/7.0.100        SDK 7.0.100   

Hope this issue can be fixed in the near future.

Hello friends,

I just wanted to share that this issue is still happening and it forced me to remove any reference to x:Double and x:String on my styles resource dictionary, so I could be able to run the application on DEBUG mode + Link SDK Assemblies only selected on iOS, just to figure out an issue on release mode only was facing. 😉

Visual Studio Community 2022 for Mac Version 17.4.3 (build 21) maui-ios 7.0.58/7.0.100 SDK 7.0.100

If you need anything from me =), please let me know I will be happy to share anything you need to reproduce the issue, however our friend @davidortinau I believe he explained it very simple and how to reproduce it.

Thanks for the help with this and anything related with .NET MAUI 👍🏻. Really appreciate it.