IMarkupExtension + XamlC does not support returning BindingBase values
See original GitHub issueDescription
I’m porting my app from xamarin forms to .net MAUI, and I faced a bug in my localized strings when I built the APK in release mode.
Debug Mode

Release Mode

Steps to Reproduce
- Create a new project
- Add localization strings binding then in the same way as below
public class LocalizationResourceManager : INotifyPropertyChanged
{
private LocalizationResourceManager()
{
AppStrings.Culture = new CultureInfo(SettingsService.CultureInfo);
}
public static LocalizationResourceManager Instance { get; } = new();
public object this[string resourceKey] =>
AppStrings.ResourceManager.GetObject(resourceKey, AppStrings.Culture) ?? Array.Empty<byte>();
public event PropertyChangedEventHandler PropertyChanged;
public void SetCulture(CultureInfo culture)
{
AppStrings.Culture = culture;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(null));
}
}
using SavioMacedo.MaoDesign.Services.Localization;
namespace SavioMacedo.MaoDesign.Services
{
[ContentProperty(nameof(Name))]
public class LocalizationService : IMarkupExtension
{
public string Name { get; set; }
public IValueConverter Converter { get; set; }
public Binding ProvideValue(IServiceProvider serviceProvider)
{
return new Binding
{
Mode = BindingMode.OneWay,
Path = $"[{Name}]",
Source = LocalizationResourceManager.Instance,
Converter = Converter
};
}
object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
{
return ProvideValue(serviceProvider);
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:services="clr-namespace:SavioMacedo.MaoDesign.Services"
xmlns:viewmodels="clr-namespace:SavioMacedo.MaoDesign.ViewModels"
xmlns:entities="clr-namespace:SavioMacedo.MaoDesign.ViewModels.Entities"
xmlns:controls="clr-namespace:SavioMacedo.MaoDesign.Platforms.Controls"
x:Class="SavioMacedo.MaoDesign.Pages.FavsPage"
x:DataType="viewmodels:FavsViewModel"
Title="{services:LocalizationService FavTitle}">
<Grid
BackgroundColor="{StaticResource DefaultBackground}">
<CollectionView
x:Name="collectionView"
ItemsSource="{Binding FavoritesEmbroidery}"
SelectionMode="Single"
Margin="10"
SelectionChangedCommand="{Binding OpenBookmarkFileCommand}"
SelectionChangedCommandParameter="{Binding Source={x:Reference collectionView}, Path=SelectedItem}">
<CollectionView.ItemsLayout>
<LinearItemsLayout
Orientation="Vertical"
ItemSpacing="10"
/>
</CollectionView.ItemsLayout>
<CollectionView.EmptyView>
<Border
BackgroundColor="White"
StrokeShape="RoundRectangle 5"
Stroke="{StaticResource PrimaryLight}">
<VerticalStackLayout
VerticalOptions="CenterAndExpand"
HorizontalOptions="FillAndExpand">
<Image
Source="empty_list.svg"
VerticalOptions="Center">
</Image>
<Label
TextColor="{StaticResource PrimaryLight}"
FontSize="Medium"
VerticalOptions="Center"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
Text="{services:LocalizationService NotFoundFavText}" />
</VerticalStackLayout>
</Border>
</CollectionView.EmptyView>
</CollectionView>
<controls:AdBanner
IsVisible="{Binding IsUnsubscribed}"
AdId="ca-app-pub-3940256099942544/6300978111"
VerticalOptions="EndAndExpand" />
</Grid>
</ContentPage>
Link to public reproduction project repository
its not a public project
Version with bug
6.0.486 (current)
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android
Did you find any workaround?
No response
Relevant log output
No response
Issue Analytics
- State:
- Created a year ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Xamarin.Forms MarkupExtension for binding
1. Text is a string, so the markup extension needs to provide a string from ProvideValue, the same as the Binding markup extension....
Read more >Creating XAML Markup Extensions - Xamarin
A XAML markup extension is a class that implements the ... XAML markup extensions define properties that contribute to the return value.
Read more >Xaml compilation causes error: "No property, bindable ...
When I set the Xaml compilation to compile, it causes the error with " No property, bindable property, or event found for 'DisplayBinding',...
Read more >Xamarin.Forms XAML Markup Extension - Code Mill Matt
Tutorial on how to use Markup Extensions and IMarkupExtension within Xamarin.Forms XAML to run code before setting property values in XAML.
Read more >[Code]-Xamarin.Forms MarkupExtension for binding
Let's start with the obvious warning: you shouldn't write your own MarkupExtensions only because it simplifies the syntax. The XF Xaml parser, and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

So a workaround is use
IMarkupExtension<BindingBase>instead.Verified this issue with Visual Studio Enterprise 17.8.0 Preview 1.0(.NET8). Can repro on android platform with sample project. Problem.Localization.App-master.zip