[FIXED] Regressed Issue: XamlCompilation error Value cannot be null, Parameter name: method

Issue

I searched SO to find this issue, but the answer didn’t work for me so the issue still exists.

Personally, I believe the issue is probably related to some configuration “thing”, but I would have no idea where to start looking to resolve it. To my knowledge, I have not altered any config settings out of norm (just used standard new project approach). Here is some detail on my issue:

Just so happens that today is first time trying out the XamlC feature. At first I tried the assembly level attribute in my App.cs file:

[assembly: XamlCompilation(XamlCompilationOptions.Compile)]

After compiling, I was getting a bunch of errors that were all identical. I also got a a different error on any page using a TemplateControl. So I pulled it off the assembly level and put a single class-level attribute on one page, and it still failed with the same error:

Value cannot be null.
Parameter name: method

I poked around on Stackoverflow and found that about a year ago someone had the same issue (here), but they said they resolved it by upgrading Xam Forms to latest version. Since I’m on the latest stable versions, I have no where to go there.

I tried this class-level attribute on several pages in my app and only found it to work on a single page in my entire app… just so happens this page has zero bindings in the XAML markup. I’m wondering if a bug was introduced that causes it to blow up.

Markup of page that doesn’t work:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Prepify.App.Pages.MainMenu"
                         xmlns:controls="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin.Abstractions"
                         BackgroundColor="White"
             Title="Menu">
    <StackLayout VerticalOptions="FillAndExpand">
        <ListView
            Header="{Binding .}"
            SeparatorColor="{StaticResource dividerColor}"
            HasUnevenRows="True"
            ItemSelected="AppMenu_OnItemSelected"
            ItemTapped="AppMenu_OnItemTapped"
            ItemsSource="{Binding Items}"
            x:Name="appMenu">

            <ListView.HeaderTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="10"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="30"/>
                            <ColumnDefinition Width="10"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="30"/>
                            <RowDefinition Height="80"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="5"/>
                        </Grid.RowDefinitions>

                        <BoxView Grid.ColumnSpan="4" Grid.RowSpan="4" BackgroundColor="{StaticResource grayDark}"/>
                        <controls:CircleImage Grid.Column="1" Grid.Row="1" HorizontalOptions="Start" VerticalOptions="End" Source="{Binding ProfileImageUrl}" WidthRequest="75" HeightRequest="75"/>
                        <Label Grid.Column="1" Grid.Row="2" Text="{Binding FullName}"/>
                        <ActivityIndicator Grid.Column="2" Grid.Row="2" IsVisible="{Binding IsBusy}" IsRunning="{Binding IsBusy}" Color="White" WidthRequest="20" HeightRequest="20" VerticalOptions="Center" />

                    </Grid>
                </DataTemplate>
            </ListView.HeaderTemplate>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Orientation="Horizontal" >
                            <StackLayout.Padding>
                                <OnPlatform x:TypeArguments="Thickness" Android="15,15,15,15" iOS="25,12,15,12" />
                            </StackLayout.Padding>
                            <Image Source="{Binding Icon}" VerticalOptions="Center" WidthRequest="20" HeightRequest="20"/>
                            <Image WidthRequest="20"/>
                            <Label Text="{Binding Label}" VerticalOptions="Center" TextColor="{Binding LabelColor}" Style="{DynamicResource ListItemTextStyle}"/>
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
</ContentPage>

Markup of only page that does work (note, no bindings anywhere):

<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    x:Class="Prepify.App.Pages.Root"
    xmlns:pages="clr-namespace:Prepify.App.Pages;assembly=Prepify.App"
    MasterBehavior="Popover"
    Title="Make Preparedness Easy">

    <MasterDetailPage.Master>
        <pages:MainMenu/>
    </MasterDetailPage.Master>

</MasterDetailPage>

I’m using all the latest as of posting this question.
Visual Studio 2015
Xamarin.Forms 2.3.3.193
Xamarin.VS 4.3.0.784

Solution

So… after getting your feedback and some from here, I just decided to try and rebuild my PCL from scratch. After hours of painstakingly migrating files over one at a time and ensuring the XamlCompilation worked at every step along the way, I got it to work build with no errors. Then I just copied the new projects I had made (2 PCLs) right over top the old ones and the solution compiled perfectly.

Answer: ??? There is none. This was a total fluke. There is nothing I learned along the way that could pinpoint the cause of the issue. If you get this issue, try rebuilding your PCL from scratch using the standard project template.

Answered By – Britton

Answer Checked By – Willingham (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published