XamlParseException Can't find button's click event method

I have researched an answer to this problem on several occasions and haven't even seen anybody else running into this issue, so I hope someone could help me out here. I have a Xamarin Forms project (only concentrating on iOS for now). All the UI is coded in the XAML file and assigning the events to the code behind. Everything was working fine yesterday, I open the project today, try to rebuild, and the app crashes as soon as it opens with XamlParseException saying it can't find the click event for my button. Nothing has changed at all with the project. A couple weeks ago this happened, and after not being able to figure it out, I simply created a new project and copied everything over to the new project. That worked for the last week or so until today. I can't recreate the project every time this arises, so I really need to figure out what is going on.

Here is a snippet of the xaml:
<?xml version="1.0" encoding="utf-8" ?>

    <OnPlatform x:TypeArguments="Thickness" iOS="0, 20, 0, 0" />

  <ScrollView x:Name="scroll_view" HorizontalOptions="Center">
      <StackLayout Spacing="0" Grid.Row="1">
        <Grid x:Name="grid_Login" RowSpacing="15" ColumnSpacing="10" WidthRequest="350" HorizontalOptions="Center">
          <... />
          <Button Image="ic_Settings.png" Clicked="BtnSettingsClicked" WidthRequest="56" HeightRequest="42"/>

And the code-behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace Pages
    public partial class LoginPage : ContentPage
        public LoginPage()

        private void BtnSettingsClicked(object sender, EventArgs args)

I'm using Visual Studio 2013, Xamarin Forms On the mac, Xamarin.iOS, Build Host If anyone could provide some insight, that would be great.


  • BrianMooreBrianMoore USMember

    Sorry I guess the 'header' part of my xaml code got clipped in the initial post, here but the class is set to:

    So the namespace does match, just to rule that out.

  • adamkempadamkemp USInsider, Developer Group Leader mod

    Did you perhaps change the linker settings to Link All?

  • BrianMooreBrianMoore USMember

    Thanks for the input Adam, but no, the settings haven't changed at all. It's set to 'Link SDK assemblies only' which I believe was default (don't remember ever changing that option after recreating the project). Literally, the application built fine when I left work the other day. First thing I did this morning was click the 'play' button in Visual Studio to launch the application and I got this error.

    Another note, I also tried cleaning the project numerous times, restarted PC, mac, and iPad, and rebuilt and still the same result.

  • adamkempadamkemp USInsider, Developer Group Leader mod

    Do you have a project you'd be willing to share so I could see it happen?

  • BrianMooreBrianMoore USMember

    Not really, I couldn't give you this application. If I create a new project, it will be fine initially just as this project was. So I really don't know how I could even show you. I will try creating a sample project, but it may take a week or two for it to start doing the same thing.

    It's a constant battle keeping Visual Studio linked to the mac Build Host, but I can usually get around it by restarting both PC and mac every morning (guess when the computer goes to sleep it messes up and won't reconnect until I reboot). So with this problem since nothing has changed in the project itself (since it just did this overnight with no one at the office), I was hoping it would be something similar in regard to the build process messing up somehow. Still hoping someone can "blindly" guess what is going on here since I would not be able to reproduce a sample project.

  • NMackayNMackay GBInsider, University mod


    I'd speak to the support team regarding both issues. Xamarin in Visual Studio creates Service Trace log files, you can use SVCUtil to read them. If you send them the log files it will help them diagnose the issue, I did them same and the data is really useful for them. We have a mac build host but we're purely an MS shop and use VS2013 and TFS. I used to have to clean the registry, temp files,un-pair and re-pair the build host and my PC (on every upgrade). As your using Studio you'll have the full licence so speak to the support team, they are really helpful.

  • BrianMooreBrianMoore USMember

    I'll definitely do that Norman. Was hoping to find someone else on here with a similar experience without having to contact Xamarin.

    For future reference, I did find that changing some of the build and linker options from their default, try to build, and then changing them back to the desired/default settings did seem to fix it. Almost like the build configuration got lost and wouldn't reset until modifying it and then resetting. Seems kind of odd, but that's my only explanation and it did get me around the situation.

    If anyone else has ran into something similar, I'd love to hear about it and what you ended up doing. Still wondering if it's just my setup/install or if this is a common issue.

  • RhonageRhonage NZMember ✭✭

    Hi @BrianMoore, I'm having the exact same issue as you (my app crashes on startup because it can't find my button Click method when it's defined in XAML.

    Have you managed to come up with a fix? The only way I can get my app working is by defining the Click events in the codebehind.


  • RhonageRhonage NZMember ✭✭
    edited June 2016

    I seem to have found a workaround.

    It looks like the Java side of things wasn't smart enough to find the method, so I added this attribute to it.

    void MyMethodName(object sender, EventArgs e) { ... }

    And now it works fine being referenced by XAML.

    Doesn't seem like a good fix though, as this means I'll have to add the attribute for each method.

    Please let me know if you have found a better way to do things. Cheers!

  • adamkempadamkemp USInsider, Developer Group Leader mod

    @Rhonage it sounds like you're using an .axml file (an Android thing), not a XAML file (a Xamarin.Forms thing). It is expected that you need to use the Export attribute for any method referenced by an .axml file because the .axml file is parsed by the Android framework itself (Java code), and your method therefore needs to be discoverable through the Java runtime. XAML is parsed by .NET code, and it uses reflection to find the method so there is no need for an Export attribute.

    The names are subtly different, which is confusing, but .axml and XAML are not the same thing.

  • RhonageRhonage NZMember ✭✭

    Hi @adamkemp,

    Thanks for the reply, but I can say with zero doubt that I'm using a XAML file. I'm currently following the following tutorial:


    And I haven't deviated from it in any way - it simply doesn't work as expected :(

    Any ideas? Thanks.

  • adamkempadamkemp USInsider, Developer Group Leader mod

    I am absolutely certain you shouldn't need an Export attribute for events called from XAML, and there is no such thing as "the Java side of things" for XAML. There is no Java involved in parsing XAML files.

  • BrianMooreBrianMoore USMember

    Hi Rohan,

    Like Adam said, you shouldn't need an export attribute for Xamarin Forms/XAML. This question is over a year old and I've actually stepped away from Xamarin for a while now so I will not be of much help. But reading through my post, changing the build settings, rebuilding, then changing them back appeared to fix my problem. If you haven't done that yet, give it a try. Otherwise, you might consider posting your own question on the forum. You will likely get much more traffic and help by doing that.

  • RhonageRhonage NZMember ✭✭

    Apologies @BrianMoore! I forgot that I'm chatting away on your thread, you're probably getting spammed. I will post my own thread shortly.

  • RhonageRhonage NZMember ✭✭

    @BrianMoore said:
    But reading through my post, changing the build settings, rebuilding, then changing them back appeared to fix my problem. If you haven't done that yet, give it a try.

    Tight chance, but do you remember which build settings you changed to fix your issue? I've tried changing the "Linker" build settings around, but no fix yet.

    Thanks again.

  • BrianMooreBrianMoore USMember

    No I don't remember. I don't even have Xamarin installed on my current PC to look. Sorry I couldn't be of much more help.

  • @Rhonage @BrianMoore
    Hey Guys I ran into the same issue you guys mentioned. However I only faced it on the iOS side(Android worked just fine)
    Good news is that I found a fix.
    For some reason when you connect to different Mac Agents the Linker information changes so under the Debug menu-> YourApp.iOS Properties... ->iOS Build (Tab)-> Linker Behavior: "Don't Link"
    This field is changing to "Link All" when ever VS wants it to. So you have to make sure it is on "Don't Link" All the time

    Hope it helps
    Mohamad Soufan

Sign In or Register to comment.