Muhand Jumah
Muhand Jumah

Reputation: 1958

Xamarin.Forms.Xaml.XamlParseException: Position 51:26

I am trying to make a custom controls library; I started by creating a project with a simple ContentView control; then I build it and import it into my second project and reference it in my XAML like this xmlns:CustomControls="clr-namespace:MXControls.Other;assembly=MXControls"

and I call my control using this line of code:

<CustomControls:Checkbox/>

But unfortunately I get this error. Xamarin.Forms.Xaml.XamlParseException: Position 51:26. Type CustomControls:Checkbox not found in xmlns clr-namespace:MXControls.Other;assembly=MXControls

I double checked the assembly name as well as namespace and they are perfectly correct.

I did further investigation and replicated that in my main project; so within my same project I created a .XAML file and did the exact samething and then referenced and it worked; but what I really want to do is create a separate project which will hold my custom controls.

Any help would be appreciated.

EDIT: In case anyone is having this issue, I got to a solution by forcing the linkage process

  1. In my library project I added a new static class and called it Infrastructure
  2. I added a static method that does nothing public static class Infrastructure { public static void init() { } }
  3. I went to my project which will import the library and under my IOS project I went to AppDelegate.cs and added Infrastructure.Init(); in the FinishedLaunching method, obviously you have to use the proper namespace e.g. using MXControls;

Full code for ios project

    using System;
    using System.Collections.Generic;
    using System.Linq;

    using Foundation;
    using UIKit;
    using MXControls3;
    namespace LeagueStalker.iOS
    {
    // The UIApplicationDelegate for the application. This class is responsible for launching the 
    // User Interface of the application, as well as listening (and optionally responding) to 
    // application events from iOS.
    [Register("AppDelegate")]
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {
        //
        // This method is invoked when the application has loaded and is ready to run. In this 
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init ();

            Infrastructure.Init();


            LoadApplication (new LeagueStalker.App ());
            UIApplication.SharedApplication.SetStatusBarStyle(UIStatusBarStyle.LightContent, false);

            return base.FinishedLaunching (app, options);

        }
    }
  }

Upvotes: 0

Views: 845

Answers (1)

Sharada
Sharada

Reputation: 13601

This is a known linking issue that is caused when all references are in XAML. You can try the options available in this answer -https://stackoverflow.com/a/43574309/7292772

Upvotes: 1

Related Questions