Search code examples
c#xamlmauiclass-library

Resolving custom library control using XmlnsDefinition (Error XFC0000)


My goal is to publish a library (as NuGet) with an XmlnsDefinition. So, first I made a minimal proof of concept with "some custom button" to be sure that I understand how this works:

[assembly: XmlnsDefinition("http://schemas.mycompany.com/concept", "ControlLibrary")]
[assembly: XmlnsPrefix("http://schemas.mycompany.com/concept", "concept")]

namespace ControlLibrary;
public partial class ButtonEx : Button
{
    public ButtonEx()
    {
        InitializeComponent();
    }
}

Found but not Resolved

So far, so good. After making a Project Reference to the control project, the library control is visible to the XAML intellisense.

intellisense popup

However, when I go to build it, the error is XFC0000. Specifically the control is visible to the compiler but cannot be "resolved".

error not resolved


Different from Not Found

Now, if the control didn't exist to begin with the error would be XLS0414 for "was not found". This experiment seems to rule that out as a cause.

error not found


My question: Is this a correct application for XmlnsDefinition and if so what is the missing glue to make the library control both visible and resolvable?


Solution

  • I can reproduce it. And inspired by .NET MAUI Library: XamlC error XFC0000: Cannot Resolve Type, Brandon Minnick's answer suggests that it is a Linker issue, and adding a name for the ButtonEx could be a workaround, e.g.

    <concept:ButtonEx x:Name="mybutton"/>
    

    Then the linker knows what you are using the library and will not remove the ControlLibrary from the project at compile time.

    Hope it helps!