Xamarin.Forms.Xaml.XamlParseException: MarkupExtension not found

Michelle picture Michelle · Oct 30, 2014 · Viewed 7.3k times · Source

I am attempting to use a a custom markup extension with Xamarin forms in order to eventually having localization implemented. I am trying to go a long the lines of the Xamarin form examples.

Here is a pieces of XAML Code that uses the extension:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:CRI.MAP.Mobile.Views;assembly=CRI.MAP.Mobile"
    x:Class="CRI.MAP.Mobile.Views.CustomerSearchPage">

    <StackLayout>
        <Button 
            Text="{local:Translate Clear}"  
            Command="{Binding ClearCommand}" />
    </StackLayout>

Here is the code for the Translation Extension Markup:

using System;
using Xamarin.Forms.Xaml;
using Xamarin.Forms;
using System.Diagnostics;

namespace CRI.MAP.Mobile.Views
{
    // You exclude the 'Extension' suffix when using in Xaml markup
    [ContentProperty ("Text")]
    public class TranslateExtension : IMarkupExtension
    {
        public string Text { get; set; }

        public object ProvideValue (IServiceProvider serviceProvider)
        {
            //if (Text == null)
            //  return null;
            //Debug.WriteLine ("Provide: " + Text);
            // Do your translation lookup here, using whatever method you require
            //var translated = L10n.Localize (Text); 

            //return translated;
            return "hello";
        }
    }
}

I commented out some of the code just in case that was the cause of the issue.

Whenever I attempt to run this I get the error: Xamarin.Forms.Xaml.XamlParseException: MarkupExtension not found for local:Translate. I am very confused as why it doesn't find the the markup extension as all the examples I look at seem to be done the same way. Does anybody know why this would be? I am having a lot of troubles in general finding good examples for Xamarin forms.

Answer

Michelle picture Michelle · Oct 30, 2014

The assembly name is wrong. I was using a shared project for Xamarin forms and had the name of the shared project as the name of the assembly. So if you have a shared project the name of the assembly needs to be the assembly that is using the shared project.