question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

x:Static in conjunction with XamlCompilation results in XFC0101 compile time error.

See original GitHub issue

Description

The following XAML snippet will result in failed compilation on a NOOB application as compiled XAML is the default for MAUI apps. Simply add it as a binding to any property.

<Binding Path="Foo" TargetNullValue="{x:Static Binding.DoNothing}"/>

Specifically the following error code is returned:

Error XFC0101 x:Static: unable to find a public -- or accessible internal -- static field, static property, const or enum value named "DoNothing" in "Binding".

It would appear that string “Binding” is somehow special during type lookup in XAML compilation operations as using another static field from the same namespace Microsoft.Maui.Controls works without error:

<Binding Path="Foo" TargetNullValue="{x:Static Application.AccentColor}"/>

Steps to Reproduce

  1. Create a new MAUI app
  2. Add the binding that causes error to one of the Image elements in MainPage.xaml
                <Image.AnchorX>
                    <Binding Path="Foo" TargetNullValue="{x:Static Binding.DoNothing}"/>
                </Image.AnchorX>
  1. Compile

Link to public reproduction project repository

https://github.com/bakerhillpins/Issues/tree/NetMauiIssue11833

Version with bug

6.0 Release Candidate 2 or older

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android, Windows, macOS, Other (Tizen, Linux, etc. not supported by Microsoft directly)

Affected platform versions

All

Did you find any workaround?

This is a Compiled Bindings issue. There are the following workarounds:

  1. Add the [XamlCompilation(XamlCompilationOptions.Skip)] Attribute to the View class in the .xaml.cs file.
  2. Create a static field/property that exists in your own namespace, reference that from the binding, and have the field redirect to the Microsoft.Maui.Controls.Binding.DoNothing field.
<Binding Path="Foo" TargetNullValue="{x:Static views:Binding.DoNothing}" />
namespace MyProject.Views
{
    public sealed class Binding
    {
        public static readonly object DoNothing = Microsoft.Maui.Controls.Binding.DoNothing;
    }
}

Relevant log output

No response

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
StephaneDelcroixcommented, Jun 28, 2023

in XAML, Binding resolves to… BindingExtension 🤦

1reaction
mattleibowcommented, Dec 8, 2022

As far as I can tell in the code, Binding.DoNothing is just for cases when using IMultiValueConverter or MultiBinding. XamlC still should not fail, but I am not sure using Binding.DoNothing is what you are looking for. It is used only in multi-bindings.

Also note to future people: even Static (not just x:Static) gives the same error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Compiled bindings - .NET MAUI
At XAML compile time, any invalid binding expressions will be reported as build errors. However, the XAML compiler will only report a build ......
Read more >
Compile time checking of bindings? - wpf
I understand the logic that the VM should know nothing of the V if everything is done correctly, but it seems that because...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found