How to Fix Error : Xamarin.Forms.Xaml.XamlParseException: Position 39:8. Type local:NoBorderEntry not found in xmlns clr-namespace:LoginApp;assembly=LoginApp

Why ?

I created a sample login form using Xamarin  and I wanted to remove the underline of the Entry controls. So I had to use a custom render to change the Entry Control .

Below Image describes what I was going to do…

2-uis

So I wrote a custom render to customize the Entry Control in Android(Droid) project and when I was trying to run the app , It gave me an exception that..

Xamarin.Forms.Xaml.XamlParseException: Position 39:8.

Type local:NoBorderEntry not found in xmlns clr-namespace:LoginApp; assembly=LoginApp

1-error

How to Solve the issue ?

So I  looked for a solution and I found the issue is in the assembly name that I have defined in the XAML file.

What I had to do is change the assembly name.

 

Now I’ll describe you what was the wrong and How did I solve the issue..

First to learn How to write a custom render for Entry Control, Click here …

Here is the architecture of my app..

3-architectire

My code..

NoBorderEntry  Class


using Xamarin.Forms;

namespace LoginApp
{
public class NoBorderEntry : Entry
{

}
}

NoBorderEntryEntryRenderer Class


using Android.Graphics.Drawables;
using LoginApp;
using LoginApp.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;

[assembly: ExportRenderer(typeof(NoBorderEntry), typeof(NoBorderEntryEntryRenderer))]
namespace LoginApp.Droid
{
public class NoBorderEntryEntryRenderer : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);

if (Control != null)
{
Control.Background = new ColorDrawable(Android.Graphics.Color.Transparent);
}
}
}
}

5-code-csharp-namespace

 

MainPage.Xaml

The XAML code is too large in my file. SO I’ll write only the important parts of the XAML code..


<?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:LoginApp;assembly=LoginApp"
x:Class="LoginApp.MainPage" >

<local:NoBorderEntry Grid.Row="0"  Grid.Column="1"  Placeholder="User Name"  PlaceholderColor="Silver" TextColor="#D6FCE6" />

</ContentPage>

And here you can see the namespace that I have declared and how we can use it to the Entry render..

4-xaml-code-1

You can see the highlighted texts in above images and according to them the namespace in the NoBorderEntryRenderer is “LoginApp.Droid” but in the in the MainPage.Xaml file the assembly name id “LoginApp”.

So “assembly=LoginApp” should me changed to “assembly=LoginApp.Droid” and the Error will be fixed.

6-fix-error

Then the correct XAML namespace declaration should be like below..

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms&quot;
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml&quot;
xmlns:local="clr-namespace:LoginApp;assembly=LoginApp.Droid"
x:Class="LoginApp.MainPage" >

</ContentPage>

Now the app will run without any error…

screenshot_20170215-233357

 

References

https://developer.xamarin.com/guides/xamarin-forms/custom-renderer/entry/

Thanks !

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s