已发布的 Maui 应用程序有在调试中不会发生的错误

问题描述 投票:0回答:0

我一直在通过开发应用程序来学习 .NET,今天我决定发布并测试它。

当我在 Microsoft Visual Studio 中以调试模式运行我的代码时,没有任何错误,一切都很顺利。

在已发布的应用程序中,登录后尝试转到主页时出现严重错误,但在调试时不会发生这种情况。

崩溃发生在用户按下登录按钮之后。我的代码检查一切是否正确并调用

await Shell.Current.GoToAsync($"//{nameof(MainPage)}");

以下是我之后得到的错误。

System.Reflection.TargetInvocationException
Message : Exception has been thrown by the target of an invocation.
StackTrace :    at Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.SetPropertyValue(Object xamlelement, XmlName propertyName, Object value, Object rootElement, INode node, HydrationContext context, IXmlLineInfo lineInfo)
   at Microsoft.Maui.Controls.Xaml.ApplyPropertiesVisitor.Visit(ValueNode node, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.ValueNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.ElementNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.RootNode.Accept(IXamlNodeVisitor visitor, INode parentNode)
   at Microsoft.Maui.Controls.Xaml.XamlLoader.Visit(RootNode rootnode, HydrationContext visitorContext, Boolean useDesignProperties)
   at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, String xaml, Assembly rootAssembly, Boolean useDesignProperties)
   at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, String xaml, Boolean useDesignProperties)
   at Microsoft.Maui.Controls.Xaml.XamlLoader.Load(Object view, Type callingType)
   at Microsoft.Maui.Controls.Xaml.Extensions.LoadFromXaml[TXaml](TXaml view, Type callingType)
   at VersionControl.Views.MainPage.InitializeComponent()
   at VersionControl.Views.MainPage..ctor(MainPageViewModel viewModel)
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.ConstructorInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
   at Microsoft.Maui.MauiContext.WrappedServiceProvider.GetService(Type serviceType)
   at Microsoft.Maui.Controls.ShellContent.<>c__DisplayClass19_0.<Microsoft.Maui.Controls.IShellContentController.GetOrCreateContent>b__0()
   at Microsoft.Maui.Controls.ElementTemplate.CreateContent()
   at Microsoft.Maui.Controls.Internals.DataTemplateExtensions.CreateContent(DataTemplate self, Object item, BindableObject container)
   at Microsoft.Maui.Controls.ShellContent.Microsoft.Maui.Controls.IShellContentController.GetOrCreateContent()
   at Microsoft.Maui.Controls.Handlers.ShellSectionHandler.SyncNavigationStack(Boolean animated, NavigationRequestedEventArgs e)
   at Microsoft.Maui.Controls.Handlers.ShellSectionHandler.MapCurrentItem(ShellSectionHandler handler, ShellSection item)
   at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0.<Add>b__0(IElementHandler h, IElement v)
   at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView)
   at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView)
   at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view)
   at Microsoft.Maui.Controls.Handlers.ShellSectionHandler.SetVirtualView(IElement view)
   at Microsoft.Maui.Controls.Handlers.ShellItemHandler.UpdateCurrentItem()
   at Microsoft.Maui.Controls.Handlers.ShellItemHandler.MapCurrentItem(ShellItemHandler handler, ShellItem item)
   at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0.<Add>b__0(IElementHandler h, IElement v)
   at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView)
   at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView)
   at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view)
   at Microsoft.Maui.Controls.Handlers.ShellItemHandler.SetVirtualView(IElement view)
   at Microsoft.Maui.Controls.Platform.ShellView.CreateShellItemView()
   at Microsoft.Maui.Controls.Platform.ShellView.SwitchShellItem(ShellItem newItem, Boolean animate)
   at Microsoft.Maui.Controls.Handlers.ShellHandler.MapCurrentItem(ShellHandler handler, Shell view)
   at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0.<Add>b__0(IElementHandler h, IElement v)
   at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView)
   at Microsoft.Maui.PropertyMapper.UpdateProperty(IElementHandler viewHandler, IElement virtualView, String property)
   at Microsoft.Maui.Handlers.ElementHandler.UpdateValue(String property)
   at Microsoft.Maui.Controls.Element.OnPropertyChanged(String propertyName)
   at Microsoft.Maui.Controls.Shell.OnPropertyChanged(String propertyName)
   at Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent)
   at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes)
   at Microsoft.Maui.Controls.ShellNavigationManager.GoToAsync(ShellNavigationParameters shellNavigationParameters, ShellNavigationRequest navigationRequest)
   at VersionControl.ViewModels.LoadingViewModel.PressMe()
System.NullReferenceException
Message : Object reference not set to an instance of an object.
StackTrace :    at Syncfusion.Maui.ListView.SfListView.SetUpKeyListenerRequirements()
   at Syncfusion.Maui.ListView.SfListView.RaiseListViewLoaded(ListViewLoadedEventArgs e)
   at Syncfusion.Maui.ListView.SfListView.ArrangeContent(Rect bounds)
   at Syncfusion.Maui.Core.SfView.set_Padding(Thickness value)
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)

几次尝试后,我注意到如果我删除我的 Syncfusion List 和 Grid 页面加载,那么问题一定在那里。

但是,我仍然不明白为什么它在调试模式下工作,而不是在已发布的应用程序中工作。

下面是我的 xaml 代码的一部分,来自主页。如果我运行这个位,它会因为 SfList 而中断。

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:viewModels="clr-namespace:VersionControl.ViewModels"
             xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
             x:Class="VersionControl.Views.MainPage"
             xmlns:syncfusionList="clr-namespace:Syncfusion.Maui.ListView;assembly=Syncfusion.Maui.ListView"
             xmlns:syncfusionGrid="clr-namespace:Syncfusion.Maui.DataGrid;assembly=Syncfusion.Maui.DataGrid"
             xmlns:core="clr-namespace:Syncfusion.Maui.Core;assembly=Syncfusion.Maui.Core"
             BackgroundColor="#212121">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="80" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="300" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <!-- First Collumn -->
        <Grid Grid.Column="0" Grid.RowSpan="2">
            <Image Source="folder_icon.png" HeightRequest="20" HorizontalOptions="Start" VerticalOptions="Start" Margin="20,45,0,0"></Image>
            <Button Text="{Binding FolderName}" Command="{Binding FolderCommand}" 
                    ToolTipProperties.Text="Click to open Windows Explorer to the default location for your projects."
                    BackgroundColor="#212121" BorderColor="#212121" Padding="0" TextColor="LightGrey" FontSize="Subtitle" Margin="50,40,0,0" 
                    MinimumHeightRequest="1" WidthRequest="120" HorizontalOptions="Start" VerticalOptions="Start" CornerRadius="4">
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroupList>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Normal"/>
                            <VisualState x:Name="PointerOver">
                                <VisualState.Setters>
                                    <Setter Property="BackgroundColor" Value="DimGrey" />
                                </VisualState.Setters>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateGroupList>
                </VisualStateManager.VisualStateGroups>
            </Button>
            <Button Text="+New" Command="{Binding AddSubFolderCommand}" BackgroundColor="#212121" BorderColor="#212121" Padding="0" 
                   TextColor="LightGrey" FontSize="Body" Margin="245,45,0,0" MinimumHeightRequest="1" WidthRequest="50" CornerRadius="4"
                   HorizontalOptions="Start" VerticalOptions="Start"
                   ToolTipProperties.Text="Create a new project and folder at the same time.">
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroupList>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Normal"/>
                            <VisualState x:Name="PointerOver">
                                <VisualState.Setters>
                                    <Setter Property="BackgroundColor" Value="DimGrey" />
                                </VisualState.Setters>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateGroupList>
                </VisualStateManager.VisualStateGroups>
            </Button>
            <syncfusionList:SfListView x:Name="listView" Padding="10" AutoFitMode="Height" ItemSpacing="10,5,0,0" Margin="10,100,0,0"
                                    ItemsSource="{Binding Projects}" SelectionMode="Single" SelectedItem="{Binding SelectedProject}" 
                                    SelectionBackground="DimGray" SelectionChangedCommand="{Binding SelectedProjectSyncCommand}">
                <syncfusionList:SfListView.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Image Source="folder2.png" HeightRequest="20" HorizontalOptions="Start" IsVisible="{Binding OnlyLocalProjectFolder}"></Image>
                            <Image Source="cloud2.png" HeightRequest="20" HorizontalOptions="Start" IsVisible="{Binding OnlyS3ProjectFolder}" Margin="0,0,0,0"></Image>
                            <Image Source="foldercloud.png" HeightRequest="20" HorizontalOptions="Start" IsVisible="{Binding LocalAndS3ProjectFolder}"></Image>
                            <Label Text="{Binding Name}" FontSize="13" TextColor="LightGrey" Margin="30,0,0,0" VerticalOptions="Center"/>
                            <Image Source="correct.png" IsVisible="false" HeightRequest="12" HorizontalOptions="End" Margin="0,0,20,0">
                                <Image.Triggers>
                                    <MultiTrigger TargetType="Image">
                                        <MultiTrigger.Conditions>
                                            <BindingCondition Binding="{Binding UpToDateLocal}" Value="true" />
                                            <BindingCondition Binding="{Binding UpToDateS3}" Value="true" />
                                        </MultiTrigger.Conditions>
                                        <Setter Property="IsVisible" Value="true" />
                                    </MultiTrigger>
                                </Image.Triggers>
                            </Image>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroupList>
                                    <VisualStateGroup>
                                        <VisualState x:Name="PointerOver">
                                            <VisualState.Setters>
                                                <Setter Property="Background" Value="DimGray"/>
                                            </VisualState.Setters>
                                        </VisualState>
                                        <VisualState x:Name="Normal"/>
                                    </VisualStateGroup>
                                </VisualStateGroupList>
                            </VisualStateManager.VisualStateGroups>
                        </Grid>
                    </DataTemplate>
                </syncfusionList:SfListView.ItemTemplate>
            </syncfusionList:SfListView>
        </Grid>

你能帮忙理解哪里出了问题吗?

c# xaml maui syncfusion
© www.soinside.com 2019 - 2024. All rights reserved.