AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / coding / 问题 / 79490498
Accepted
Prescott Chartier
Prescott Chartier
Asked: 2025-03-07 03:36:58 +0800 CST2025-03-07 03:36:58 +0800 CST 2025-03-07 03:36:58 +0800 CST

Maui App 连接到 Visual Studio 时以调试模式运行,但独立运行时崩溃

  • 772

我已将问题缩小到Flyout菜单 xaml 代码中的某个部分,但无法查明原因。我的 xaml:

        <VerticalStackLayout
            x:Name="Flyout"
            WidthRequest="260"
            HorizontalOptions="Start"
            Spacing="2"
            Grid.Row="1"
            BackgroundColor="Gold"
            TranslationX="-250">
            <HorizontalStackLayout HorizontalOptions="Start" HeightRequest="50" >
                <Image Source="addEmployee.jpg" Style="{StaticResource IconLabelStyle}" />
                <Label x:Name="AddEmployee" Text="Add Employee" Style="{StaticResource LabelStyle}" />
                <HorizontalStackLayout.GestureRecognizers>
                    <TapGestureRecognizer Tapped="OnMenuItemTap" CommandParameter="Add Another Participant"/>
                </HorizontalStackLayout.GestureRecognizers>
            </HorizontalStackLayout>
            <HorizontalStackLayout HorizontalOptions="Start" HeightRequest="50">
                <Image Source="assign.jpg" Style="{StaticResource IconLabelStyle}" />
                <Label x:Name="Assign" Text="Assign Employee To Section" Style="{StaticResource LabelStyle}" />
                <HorizontalStackLayout.GestureRecognizers>
                    <TapGestureRecognizer Tapped="OnMenuItemTap" CommandParameter="Re-Register"/>
                </HorizontalStackLayout.GestureRecognizers>
            </HorizontalStackLayout>
            <HorizontalStackLayout HorizontalOptions="Start" HeightRequest="50">
                <Image Source="text.jpg" Style="{StaticResource IconLabelStyle}" />
                <Label x:Name="sendtext" Text="Send Text" Style="{StaticResource LabelStyle}" />
                <HorizontalStackLayout.GestureRecognizers>
                    <TapGestureRecognizer Tapped="OnMenuItemTap" CommandParameter="ChatRoom"/>
                </HorizontalStackLayout.GestureRecognizers>
            </HorizontalStackLayout>
            <HorizontalStackLayout HorizontalOptions="Start" HeightRequest="50">
                <Image Source="myaccount.jpg" Style="{StaticResource IconLabelStyle}" />
                <Label x:Name="MyAccount" Text="My Account" Style="{StaticResource LabelStyle}" />
                <HorizontalStackLayout.GestureRecognizers>
                    <TapGestureRecognizer Tapped="OnMenuItemTap" CommandParameter="My Account"/>
                </HorizontalStackLayout.GestureRecognizers>
            </HorizontalStackLayout>
            <HorizontalStackLayout HorizontalOptions="Start" HeightRequest="50">
                <Image Source="myaccount.jpg" Style="{StaticResource IconLabelStyle}" />
                <Label x:Name="LogOut" Text="Log Off" Style="{StaticResource LabelStyle}" />
                <HorizontalStackLayout.GestureRecognizers>
                    <TapGestureRecognizer Tapped="OnMenuItemTap" CommandParameter="Log Off"/>
                </HorizontalStackLayout.GestureRecognizers>
            </HorizontalStackLayout>
        </VerticalStackLayout>

当我注释掉Flyout代码时,应用程序将在调试器之外运行。我转储了测试设备崩溃日志,在其中发现了以下内容:

03-05 20:52:00.570 10573  4825  4825 I MonoDroid: UNHANDLED EXCEPTION:
03-05 20:52:00.575 10573  4825  4825 I MonoDroid: Android.Runtime.JavaProxyThrowable: Exception of type 'Android.Runtime.JavaProxyThrowable' was thrown.
03-05 20:52:00.575 10573  4825  4825 I MonoDroid: 
03-05 20:52:00.575 10573  4825  4825 I MonoDroid:   --- End of managed Android.Runtime.JavaProxyThrowable stack trace ---
03-05 20:52:00.575 10573  4825  4825 I MonoDroid: android.runtime.JavaProxyThrowable: [System.InvalidCastException]: Specified cast is not valid.
03-05 20:52:00.575 10573  4825  4825 I MonoDroid:   at Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.SetPropertyValue + 0xb9(Unknown Source)
03-05 20:52:00.575 10573  4825  4825 I MonoDroid:   at Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.Visit + 0xf6(Unknown Source)
03-05 20:52:00.575 10573  4825  4825 I MonoDroid:   at Microsoft.Maui.Controls.Xaml.ElementNode.Accept + 0x90(Unknown Source)
03-05 20:52:00.575 10573  4825  4825 I MonoDroid:   at Microsoft.Maui.Controls.Xaml.ElementNode.Accept + 0x3e(Unknown Source)
03-05 20:52:00.575 10573  4825  4825 I MonoDroid:   at Microsoft.Maui.Controls.Xaml.ElementNode.Accept + 0x67(Unknown Source)
03-05 20:52:00.575 10573  4825  4825 I MonoDroid:   at Microsoft.Maui.Controls.Xaml.ElementNode.Accept + 0x67(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at Microsoft.Maui.Controls.Xaml.ElementNode.Accept + 0x67(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at Microsoft.Maui.Controls.Xaml.ElementNode.Accept + 0x67(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at Microsoft.Maui.Controls.Xaml.RootNode.Accept + 0x81(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at Microsoft.Maui.Controls.Xaml.XamlLoader.Visit + 0x97(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at Microsoft.Maui.Controls.Xaml.XamlLoader.Load + 0x9d(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at Microsoft.Maui.Controls.Xaml.XamlLoader.Load + 0x0(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at Microsoft.Maui.Controls.Xaml.XamlLoader.Load + 0x29(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at Microsoft.Maui.Controls.Xaml.Extensions.LoadFromXaml + 0x0(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at MyApp.RegUser.InitializeComponent + 0x1(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at MyApp.RegUser..ctor + 0xa0(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at MyApp.Logon+<SignOn>d__6.MoveNext + 0x7b6(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw + 0x11(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess + 0x37(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification + 0x2d(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd + 0x8(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at System.Runtime.CompilerServices.TaskAwaiter.GetResult + 0x0(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at MyApp.Logon+<<OnCounterClicked>b__5_0>d.MoveNext + 0x73(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw + 0x11(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess + 0x37(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification + 0x2d(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd + 0x8(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at System.Runtime.CompilerServices.TaskAwaiter.GetResult + 0x0(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at MyApp.Logon+<OnCounterClicked>d__5.MoveNext + 0xf4(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw + 0x11(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at System.Threading.Tasks.Task+<>c.<ThrowAsync>b__128_0 + 0x0(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 + 0x0(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at Java.Lang.Thread+RunnableImplementor.Run + 0x8(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at Java.Lang.IRunnableInvoker.n_Run + 0x0(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V + 0x5(Unknown Source)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at mono.java.lang.RunnableImplementor.n_run(Native Method)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:29)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at android.os.Handler.handleCallback(Handler.java:958)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at android.os.Looper.loopOnce(Looper.java:230)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at android.os.Looper.loop(Looper.java:319)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at android.app.ActivityThread.main(ActivityThread.java:9063)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at java.lang.reflect.Method.invoke(Native Method)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:588)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
03-05 20:52:00.576 10573  4825  4825 I MonoDroid: 
03-05 20:52:00.576 10573  4825  4825 I MonoDroid:   --- End of managed Android.Runtime.JavaProxyThrowable stack trace ---

此行出现错误Specified cast is not valid. at Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.SetPropertyValue + 0xb9(Unknown Source)

我没有在其中看到任何可以确定演员异常的信息。也许另一双眼睛可以找到。

maui
  • 1 1 个回答
  • 28 Views

1 个回答

  • Voted
  1. Best Answer
    Prescott Chartier
    2025-03-07T08:27:06+08:002025-03-07T08:27:06+08:00

    我逐行注释掉代码,直到应用程序运行而不会在调试器外崩溃。结果发现Style="{StaticResource IconLabelStyle}`每个Image标签中的行都是崩溃的根源。样式的定义包含在ResourceDictionary我下面发布的文件中。

        <ResourceDictionary\>  
            <Style x:Key="IconLabelStyle" TargetType="Label"\>  
                <Setter Property="FontSize" Value="Medium" /\>  
                <Setter Property="WidthRequest" Value="50" /\>  
                <Setter Property="VerticalTextAlignment" Value="Center" /\>  
                <Setter Property="HorizontalTextAlignment" Value="Center" /\>  
                <Setter Property="TextColor" Value="Black" /\>  
                <Setter Property="BackgroundColor" Value="Gold" /\>  
            </Style\>  
            <Style x:Key="LabelStyle" TargetType="Label"\>  
                <Setter Property="VerticalTextAlignment" Value="Center" /\>  
                <Setter Property="Padding" Value="5,5" /\>  
                <Setter Property="FontSize" Value="Medium" /\>  
                <Setter Property="BackgroundColor" Value="Gold" /\>  
            </Style\>  
        </ResourceDictionary\>  
    

    如您所见,ResourceDictionary TargetType=Label绝对不是标签。显然,编译器无法识别这些东西。这可以节省我很多时间。我Image为 添加了样式ResourceDisctionary,现在它变成了:

            <ResourceDictionary>
                <Style x:Key="IconImageStyle" TargetType="Image">
                    <Setter Property="WidthRequest" Value="20" />
                    <Setter Property="HeightRequest" Value="20"/>
                    <Setter Property="VerticalOptions"  Value="Center" />
                    <Setter Property="HorizontalOptions" Value="Center" />
                    <Setter Property="BackgroundColor" Value="Gold" />
                </Style>
                <Style x:Key="IconLabelStyle" TargetType="Label">
                    <Setter Property="FontSize" Value="Medium" />
                    <Setter Property="WidthRequest" Value="50" />
                    <Setter Property="VerticalTextAlignment" Value="Center" />
                    <Setter Property="HorizontalTextAlignment" Value="Center" />
                    <Setter Property="TextColor" Value="Black" />
                    <Setter Property="BackgroundColor" Value="Gold" />
                </Style>
                <Style x:Key="LabelStyle" TargetType="Label">
                    <Setter Property="VerticalTextAlignment" Value="Center" />
                    <Setter Property="Padding" Value="5,5" />
                    <Setter Property="FontSize" Value="Medium" />
                    <Setter Property="BackgroundColor" Value="Gold" />
                </Style>
            </ResourceDictionary>
    
    • 1

相关问题

  • 在图像上获取圆角

  • 如何从MAUI控件中导出并设置样式?

  • 毛伊岛地图 - 如何从位置获取地址、城市和国家/地区名称?

  • .NET Maui CollectionView,如何仅在值存在时显示值

  • ScrollView 不适用于 android 上的 collectionView 中的 ItemTemplte

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve