You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Xamarin.Forms.CarouselView Android启动崩溃排查求助

Xamarin.Forms.CarouselView 加载失败导致Android模拟器崩溃排查问题

问题背景

使用VS2022开发,当前Xamarin.Forms.CarouselView版本为4.7.0.1351,程序在Android模拟器启动后闪屏结束即崩溃,报错System.IO.FileNotFoundException,提示无法加载文件'Xamarin.Forms.CarouselView'。已尝试将Xamarin.Forms从5版本降级到4版本、修改链接行为为None,均未解决问题。此前使用的是已弃用的CarouselView类,迁移到官方CarouselView后出现该问题,崩溃发生在业务代码执行前。

错误日志

Time    Device Name Type    PID Tag Message
08-15 00:17:10.834  pixel_5_-_api_33    Info    15744   MonoDroid   File name: 'Xamarin.Forms.CarouselView'
  at System.AppDomain.Load (System.String assemblyString, System.Security.Policy.Evidence assemblySecurity, System.Boolean refonly, System.Threading.StackCrawlMark& stackMark) [0x00016] in <4bce72284db54ba88918eb2574cfbcac>:0 
  at System.AppDomain.Load (System.String assemblyString) [0x00002] in <4bce72284db54ba88918eb2574cfbcac>:0 
  at (wrapper remoting-invoke-with-check) System.AppDomain.Load(string)
  at System.Reflection.Assembly.Load (System.String assemblyString) [0x00005] in <4bce72284db54ba88918eb2574cfbcac>:0 
  at xxx.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x00084] in <3f9ff841a5de44a3990d704b23c5b075>:0 
  at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x0000f] in <e579b44edd2a422a959322ed2d270ce9>:0 
  at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V (_JniMarshal_PPL_V callback, System.IntPtr jnienv, System.IntPtr klazz, System.IntPtr p0) [0x00005] in <e579b44edd2a422a959322ed2d270ce9>:0 
    at crc649c631d1a2337722a.MainActivity.n_onCreate(Native Method)
    at crc649c631d1a2337722a.MainActivity.onCreate(MainActivity.java:33)
    at android.app.Activity.performCreate(Activity.java:8305)
    at android.app.Activity.performCreate(Activity.java:8284)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1417)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3626)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3782)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7872)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)


 Time   Device Name Type    PID Tag Message
    08-16 10:42:58.600  pixel_5_-_api_33    Info    4877    MonoDroid   android.runtime.JavaProxyThrowable: System.IO.FileNotFoundException: Could not load the file 'Xamarin.Forms.CarouselView'.
    08-16 10:42:58.600  pixel_5_-_api_33    Info    4877    MonoDroid   Android.Runtime.JavaProxyThrowable: Exception of type 'Android.Runtime.JavaProxyThrowable' was thrown.
      --- End of managed Android.Runtime.JavaProxyThrowable stack trace ---
Time    Device Name Type    PID Tag Message
08-16 10:42:58.600  pixel_5_-_api_33    Info    4877    MonoDroid   Android.Runtime.JavaProxyThrowable: Exception of type 'Android.Runtime.JavaProxyThrowable' was thrown.
  --- End of managed Android.Runtime.JavaProxyThrowable stack trace ---

08-16 10:42:58.580  pixel_5_-_api_33    Info    4877    MonoDroid   UNHANDLED EXCEPTION:
08-16 10:42:58.557  pixel_5_-_api_33    Error   4877    AndroidRuntime  File name: 'Xamarin.Forms.CarouselView'
  at System.AppDomain.Load (System.String assemblyString, System.Security.Policy.Evidence assemblySecurity, System.Boolean refonly, System.Threading.StackCrawlMark& stackMark) [0x00016] in <f343918e3e674e26b0a87116fddf1ef1>:0 
  at System.AppDomain.Load (System.String assemblyString) [0x00002] in <f343918e3e674e26b0a87116fddf1ef1>:0 
  at (wrapper remoting-invoke-with-check) System.AppDomain.Load(string)
  at System.Reflection.Assembly.Load (System.String assemblyString) [0x00005] in <f343918e3e674e26b0a87116fddf1ef1>:0 
  at xxx.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x00084] in <a58ddd8452a74a9b95cf722eeea8395b>:0 
  at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x0000f] in <dff511789b744bd7b4f24a4879d8f7d2>:0 
  at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V (_JniMarshal_PPL_V callback, System.IntPtr jnienv, System.IntPtr klazz, System.IntPtr p0) [0x00005] in <dff511789b744bd7b4f24a4879d8f7d2>:0 
    at crc649c631d1a2337722a.MainActivity.n_onCreate(Native Method)
    at crc649c631d1a2337722a.MainActivity.onCreate(MainActivity.java:33)
    at android.app.Activity.performCreate(Activity.java:8305)
    at android.app.Activity.performCreate(Activity.java:8284)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1417)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3626)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3782)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7872)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
08-16 10:42:58.557  pixel_5_-_api_33    Error   4877    AndroidRuntime  android.runtime.JavaProxyThrowable: System.IO.FileNotFoundException: Could not load the file 'Xamarin.Forms.CarouselView'.

相关XAML代码片段

<?xml version="1.0" encoding="utf-8" ?>
<local:BaseContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:xxx.Core.Base.Views;assembly=xxx.Core"
             xmlns:helpers="clr-namespace:xxx.Core.Admin.Helpers;assembly=xxx.Core"
             xmlns:extensions="clr-namespace:xxx.Core.Base.Extensions;assembly=xxx.Core"
             xmlns:classes="clr-namespace:xxx.Core.Classes;assembly=xxx.Core"
             xmlns:cv="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.CarouselView"
             x:Class="xxx.Core.Admin.Views.LaunchAppPG"
             SizeChanged="OnPageSizeChanged"
             Title="{Binding Title}"
             Padding="0">

  <ContentPage.Resources>
    <ResourceDictionary>
      <extensions:BoolConverter x:Key="BoolConverter"/>
    </ResourceDictionary>
  </ContentPage.Resources>

  <Grid x:Name="MainGrid" RowSpacing="0" ColumnSpacing="0">
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto" />
      <RowDefinition Height="Auto" />
      <RowDefinition Height="11*" />
      <RowDefinition Height="2*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="*" />
      <ColumnDefinition Width="0" />
    </Grid.ColumnDefinitions>
    <Image Grid.Row="0" Grid.RowSpan="4" Grid.Column="0" Grid.ColumnSpan="2" Source="Background.jpg" Aspect="AspectFill" />
    <Label Grid.Row="0" Grid.Column="0" Text="{Binding Hotel.Name}" FontSize="Large" FontAttributes="Bold" TextColor="Black" HorizontalTextAlignment="Center" HorizontalOptions="CenterAndExpand" />
    <StackLayout x:Name="CarouselIndicator" Grid.Row="1" Grid.Column="0" Orientation="Horizontal" HorizontalOptions="CenterAndExpand" HeightRequest="18" Padding="6">

    </StackLayout>
    <cv:CarouselView x:Name="CarouselApps" ItemsSource="{Binding UserAppList}" Grid.Row="2" Grid.Column="0" Position="{Binding CarouselPosition}" >
      <cv:CarouselView.ItemTemplate>
        <DataTemplate>
          <Grid VerticalOptions="Center">
            <Grid.RowDefinitions>
              <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="*" />
              <ColumnDefinition Width="5*" />
              <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <ListView Grid.Row="0" Grid.Column="1" ItemsSource="{Binding MenuCommands}" SeparatorVisibility="None" VerticalOptions="Center" HasUnevenRows="True">
              <ListView.ItemTemplate>
                <DataTemplate>
                  <ViewCell>
                    <Grid Padding="6">
                      <Button TextColor="White"
                              BackgroundColor="{x:Static helpers:AppColors.SEMITRANS}"
                              BorderColor="{x:Static helpers:AppColors.MAXBLUEDARKER}"
                              BorderWidth="2" Command="{Binding MenuCommand}" Text="{Binding CommandName}"
                              BorderRadius="1" />
                    </Grid>
                  </ViewCell>
                </DataTemplate>
              </ListView.ItemTemplate>
            </ListView>
          </Grid>
        </DataTemplate>
      </cv:CarouselView.ItemTemplate>
    </cv:CarouselView>

    ...
  </Grid>

</local:BaseContentPage>

相关C#代码片段

public partial class LaunchAppPG : xxx.Core.Base.Views.BaseContentPage
{
    private List<Image> IndicatorList = new List<Image>();
    const string IndicatorImage = "CarouselIndicator.png";
    const string IndicatorSelectedImage = "CarouselIndicatorSelected.png";

    public LaunchAppPG()
    {
        InitializeComponent();
        NavigationPage.SetHasBackButton(this, false);
        
        // CarouselApps.ItemSelected += OnCarouselItemSelected;
        CarouselApps.PropertyChanged += OnCarouselPropertyChanged;
    }
}

排查步骤

  • 核对NuGet包版本一致性:确认所有项目(共享项目、Android项目)的Xamarin.Forms和Xamarin.Forms.CarouselView版本均为4.7.0.1351,无版本差异;尝试卸载相关包后清理解决方案,再重新安装指定版本。
  • 检查Android项目引用:右键Android项目→属性→引用,确认Xamarin.Forms.CarouselView已正确添加,若缺失则手动通过NuGet安装。
  • 验证XAML命名空间:确认XAML中xmlns:cv="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.CarouselView"的程序集名称正确,4.x版本中该命名空间需对应单独的CarouselView包。
  • 清理重建解决方案:执行清理操作,删除所有项目的bin和obj文件夹后重新编译,清除旧编译文件残留。
  • 调整链接行为:尝试将Android项目链接行为从None改为Sdk Assemblies Only,关闭AOT编译(若开启),避免程序集被错误裁剪。
  • 检查MainActivity初始化:确认Forms.Init(this, bundle)在MainActivity.OnCreate中正确执行,无遗漏初始化步骤或手动加载程序集的异常逻辑。
  • 空项目验证:创建新Xamarin.Forms项目,安装相同版本的包并添加简单CarouselView代码,若新项目正常则说明原项目存在配置或残留问题,逐步迁移代码排查。

适合搜索的关键词

  • Xamarin.Forms.CarouselView System.IO.FileNotFoundException Android
  • Xamarin.Forms.CarouselView 无法加载程序集 Android
  • Xamarin.Forms 4.7 CarouselView 启动崩溃
  • Xamarin.Forms 迁移CarouselView 加载失败

内容的提问来源于stack exchange,提问作者Yohanes AI

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 15:45:54