退化问题:XamlCompilation错误值不能为空,参数名:方法论

13z8s7eq  于 2022-12-07  发布在  其他
关注(0)|答案(3)|浏览(106)

我搜索了SO以找到this问题,但答案对我不起作用,因此问题仍然存在。
就我个人而言,我相信这个问题可能与一些配置"事情"有关,但是我不知道从哪里开始寻找解决它的方法。据我所知,我没有改变任何超出规范的配置设置(只是使用了标准的新项目方法)。下面是关于我的问题的一些细节:
碰巧今天是第一次尝试XamlC特性。首先我在App.cs文件中尝试了程序集级属性:

[assembly: XamlCompilation(XamlCompilationOptions.Compile)]

编译后,我得到了一堆完全相同的错误。我还得到了一个不同的错误在任何页面上使用一个模板控件。所以我把它从程序集级别,并把一个单一的类级别的属性在一个页面上,它仍然失败,并与相同的错误:

Value cannot be null.
Parameter name: method

我在Stackoverflow上查了一下,发现大约一年前有人遇到过同样的问题(在这里),但他们说他们通过将Xam Forms升级到最新版本来解决这个问题。
我在我的应用程序中的几个页面上尝试了这个类级属性,但只发现它在我的整个应用程序中的一个页面上工作......碰巧这个页面在XAML标记中没有绑定。我想知道是否引入了一个bug,导致它崩溃。
无法使用的页面标记:

<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>

仅标记可正常工作的页面(注意,任何地方都没有绑定):

<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

2nbm6dog

2nbm6dog1#

我有一个完全相同的问题,正好包含一个页面(xaml + cs)和一个ViewModel的项目。我改变了一行,保存的机会,它没有建立了,也与这个错误:

Value cannot be null.
Parameter name: method

在我的例子中,改变包的版本修复了它。只要右键点击你的项目〉打开属性〉打开左边的包标签〉并增加包的版本号。当然,我对我的解决方案做了很多清理和重建。
这对我很有效,但我必须承认,我刚刚开始使用Xamarin,所以我真的不知道我在做什么:D也许这对任何人都有帮助。
哦,也许重要的是要说:我在Visual Studio 2017中使用Xamarin 3.2.0.839982

dohp0rv5

dohp0rv52#

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.

jogvjijk

jogvjijk3#

警告:这不是一个正确的答案,但这太长了,不适合评论。那就回答吧。
我将您粘贴的XAML用于一个全新的Xamarin.Forms项目(参考XF 2.3.3.180(也尝试使用.193)和ImageCircle 1.8.1),删除了两个事件处理程序,添加了[XamlCompilation]属性,它编译得很好。
如果你不能缩小你的问题范围,并且仍然认为这是Xamarin.Forms中的问题,你应该在https://bugzilla.xamarin.com/enter_bug.cgi?product=Forms上打开一个带有复制案例的bug报告。当它完成时,你甚至可以ping我,这样我就可以查看它。

相关问题