C# 由于自定义样式,使用.NET本机工具链编译的UWP应用程序在启动时崩溃

C# 由于自定义样式,使用.NET本机工具链编译的UWP应用程序在启动时崩溃,c#,xaml,xamarin.forms,uwp,uwp-xaml,C#,Xaml,Xamarin.forms,Uwp,Uwp Xaml,我已经证实,在Xamarin Forms UWP项目的App.xaml ResourceDictionary中仅存在以下样式(即使没有使用)就会导致UWP应用程序在启动时崩溃,因为在发布模式下启用了.NET本机工具链(x64,但不认为在这种情况下有什么关系)。如果不启用.NET本机工具链,则可以100%正常工作,但我确实希望保留此自定义样式,并从本机编译的更快应用程序中获益。有人知道为什么它会使应用程序崩溃吗?除了我在Windows事件查看器中看到的错误消息之外,我甚至想不出如何获得更详细的错误

我已经证实,在Xamarin Forms UWP项目的App.xaml ResourceDictionary中仅存在以下样式(即使没有使用)就会导致UWP应用程序在启动时崩溃,因为在发布模式下启用了.NET本机工具链(x64,但不认为在这种情况下有什么关系)。如果不启用.NET本机工具链,则可以100%正常工作,但我确实希望保留此自定义样式,并从本机编译的更快应用程序中获益。有人知道为什么它会使应用程序崩溃吗?除了我在Windows事件查看器中看到的错误消息之外,我甚至想不出如何获得更详细的错误消息,它只是说Windows.UI.Xaml.dll是出错的模块名

更新:通过关闭“优化代码”并在发布模式下启用调试并从VS运行,我能够获得以下信息。。。。这让我找到了一个我正在使用的名为。。。仍然不确定我的UWP app.xaml中的自定义样式与此问题之间的联系,但修复此真正的问题当然解决了所有问题(即,此样式是一个危险的问题)。在下面添加了关于此问题的答案

System.Private.Interop.dll!System.Runtime.InteropServices.McgMarshall.ThrowOnExternalCallFailed(int hr,System.RuntimeTypeHandle typeHnd)第1189行 f:\dd\ndp\fxcore\CoreRT\src\System.Private.Interop\src\Shared\mcgmail.cs(1189)

System.ArgumentException HResult=0x80070057消息=值不正确 在预期范围内。Source=StackTrace:StackTrace“在 System.Runtime.InteropServices.McgMarshall.ThrowOnExternalCallFailed(Int32 hr,运行时类型句柄类型HND)在 f:\dd\ndp\fxcore\CoreRT\src\System.Private.Interop\src\Shared\mcgmail.cs:line 1189\r\n在\uuuu Interop.ComCallHelpers.Call(\uuu ComObject\uuu this, RuntimeTypeHandle\uuuTypeHnd,Int32\uuuuTargetIndex,双arg0)\r\n
在Interop.ForwardComStubs.Stub\u 22[t此](\u ComObject\u此,双精度) 值,Int32\uuuu targetIndex)\r\n位于 Windows.UI.Xaml.IUIElement\uuuuu Impl.Stubs.put\u Opacity(\uuuu ComObject\uuuu this, 双值)\r\n在Windows.UI.Xaml.UIElement.put\u不透明度(双值) 值)\r\n位于 Xamarin.Forms.Platform.UWP.VisualElementTracker
2.UpdateCapacity(VisualElement
视图,框架元素(框架元素)
D:\\a\\1\\s\\Xamarin.Forms.Platform.UAP\\VisualElementTracker.cs:line
518\r\n在
Xamarin.Forms.Platform.UWP.VisualElementTracker
2.UpdateNativeControl() 在里面 D:\a\1\s\Xamarin.Forms.Platform.UAP\VisualElementTracker.cs:line 236\r\n在 Xamarin.Forms.Platform.UWP.VisualElementTracker
2.OnRedrawRequired(对象
发件人,事件参数(e)在
D:\\a\\1\\s\\Xamarin.Forms.Platform.UAP\\VisualElementTracker.cs:line
409\r\n位于System.EventHandler
1.Invoke(对象发送方,TEventArgs e) \r\n位于中的Xamarin.Forms.VisualElement.BatchCommit() D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:第572行\r\n Xamarin.Forms.AnimationExtensions.HandleTweenerUpdated(对象o, 事件args args)中 D:\a\1\s\Xamarin.Forms.Core\AnimationExtensions.cs:第274行\r\n
在System.EventHandler.InvokePenstaticThunk(对象发送方,EventArgs e) \r\n在System.EventHandler.Invoke(对象发送方,EventArgs e)\r\n 在Xamarin.Forms.Tweener.b_uu22_u0(Int64步)中 D:\a\1\s\Xamarin.Forms.Core\Tweener.cs:第92行\r\n System.Func
2.Invoke(T arg)\r\n位于
中的Xamarin.Forms.Internals.Ticker.SendSignals(Int64步骤)
D:\\a\\1\\s\\Xamarin.Forms.Core\\internal\\Ticker.cs:第136行\r\n
在中的Xamarin.Forms.Internals.Ticker.SendSignals(Int32 timestep)处 D:\\a\\1\\s\\Xamarin.Forms.Core\\internal\\Ticker.cs:第125行\r\n
在 Xamarin.Forms.Platform.UWP.WindowsTicker.RenderingFrameEventHandler(对象 发件人,对象args)位于 D:\\a\\1\\s\\Xamarin.Forms.Platform.UAP\\WindowsTicker.cs:第25行\r\n 在System.EventHandler中
1.Invoke(对象发送方,TEventArgs e)\r\n在 __Interop.Intrinsics.HasThisCall\uu51(对象\uuuu this,IntPtr pfn,对象arg0,对象arg1)\r\n位于\uuuu Interop.ReverseComStubs.Stub\u41(对象 __此字符串为Void*unsafe_sender、Void*unsafe_args、IntPtr\uu methodPtr)“字符串


        <Style x:Key="FormTextBoxStyle" TargetType="uwp:FormsTextBox">
            <Setter Property="MinWidth" Value="{ThemeResource TextControlThemeMinWidth}" />
            <Setter Property="MinHeight" Value="{ThemeResource TextControlThemeMinHeight}" />
            <Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}" />
            <Setter Property="ForegroundFocusBrush" Value="{ThemeResource SystemControlForegroundChromeBlackHighBrush}" />
            <Setter Property="PlaceholderForegroundBrush" Value="{ThemeResource SystemControlPageTextBaseMediumBrush}" />
            <Setter Property="PlaceholderForegroundFocusBrush" Value="{ThemeResource SystemControlPageTextChromeBlackMediumLowBrush}" />
            <Setter Property="Background" Value="{ThemeResource SystemControlBackgroundAltHighBrush}" />
            <Setter Property="BackgroundFocusBrush" Value="{ThemeResource SystemControlBackgroundChromeWhiteBrush}" />
            <Setter Property="BorderBrush" Value="{ThemeResource SystemControlForegroundChromeDisabledLowBrush}" />
            <Setter Property="SelectionHighlightColor" Value="{ThemeResource SystemControlHighlightAccentBrush}" />
            <Setter Property="BorderThickness" Value="0,0,0,2" />
            <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
            <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
            <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden" />
            <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden" />
            <Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False" />
            <Setter Property="Padding" Value="0" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="uwp:FormsTextBox">
                        <Grid>
                            <Grid.Resources>

                                <Style x:Name="DeleteButtonStyle" TargetType="Button">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="Button">
                                                <Grid
                                                    x:Name="ButtonLayoutGrid"
                                                    Background="{ThemeResource TextBoxButtonBackgroundThemeBrush}"
                                                    BorderBrush="{ThemeResource TextBoxButtonBorderThemeBrush}"
                                                    BorderThickness="{TemplateBinding BorderThickness}">
                                                    <TextBlock
                                                        x:Name="GlyphElement"
                                                        HorizontalAlignment="Center"
                                                        VerticalAlignment="Center"
                                                        AutomationProperties.AccessibilityView="Raw"
                                                        FontFamily="{ThemeResource SymbolThemeFontFamily}"
                                                        FontSize="12"
                                                        FontStyle="Normal"
                                                        Foreground="{TemplateBinding Foreground}"
                                                        Text="&#xE10A;" />
                                                    <VisualStateManager.VisualStateGroups>
                                                        <VisualStateGroup x:Name="CommonStates">
                                                            <VisualState x:Name="Normal" />
                                                            <VisualState x:Name="PointerOver">
                                                                <Storyboard>
                                                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GlyphElement" Storyboard.TargetProperty="Foreground">
                                                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAccentBrush}" />
                                                                    </ObjectAnimationUsingKeyFrames>
                                                                </Storyboard>
                                                            </VisualState>
                                                            <VisualState x:Name="Pressed">
                                                                <Storyboard>
                                                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonLayoutGrid" Storyboard.TargetProperty="Background">
                                                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAccentBrush}" />
                                                                    </ObjectAnimationUsingKeyFrames>
                                                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GlyphElement" Storyboard.TargetProperty="Foreground">
                                                                        <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltChromeWhiteBrush}" />
                                                                    </ObjectAnimationUsingKeyFrames>
                                                                </Storyboard>
                                                            </VisualState>
                                                            <VisualState x:Name="Disabled">
                                                                <Storyboard>
                                                                    <DoubleAnimation
                                                                        Storyboard.TargetName="ButtonLayoutGrid"
                                                                        Storyboard.TargetProperty="Opacity"
                                                                        To="0"
                                                                        Duration="0" />
                                                                </Storyboard>
                                                            </VisualState>
                                                        </VisualStateGroup>
                                                    </VisualStateManager.VisualStateGroups>
                                                </Grid>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>

                            </Grid.Resources>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>
                            <Border
                                x:Name="BackgroundElement"
                                Grid.Row="1"
                                Grid.RowSpan="1"
                                Grid.ColumnSpan="2"
                                Margin="{TemplateBinding BorderThickness}"
                                Background="{TemplateBinding Background}" />
                            <Border
                                x:Name="BorderElement"
                                Grid.Row="1"
                                Grid.RowSpan="1"
                                Grid.Column="0"
                                Grid.ColumnSpan="2"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}" />
                            <ContentPresenter
                                x:Name="HeaderContentPresenter"
                                Grid.Row="0"
                                Grid.Column="0"
                                Grid.ColumnSpan="2"
                                VerticalAlignment="Bottom"
                                VerticalContentAlignment="Bottom"
                                x:DeferLoadStrategy="Lazy"
                                Content="{TemplateBinding Header}"
                                ContentTemplate="{TemplateBinding HeaderTemplate}"
                                FontWeight="Normal"
                                Foreground="{ThemeResource SystemControlForegroundBaseHighBrush}"
                                Visibility="Collapsed" />
                            <ScrollViewer
                                x:Name="ContentElement"
                                Grid.Row="0"
                                Grid.RowSpan="2"
                                Grid.Column="0"
                                Margin="{TemplateBinding BorderThickness}"
                                Padding="{TemplateBinding Padding}"
                                VerticalAlignment="Center"
                                AutomationProperties.AccessibilityView="Raw"
                                Foreground="{TemplateBinding ForegroundFocusBrush}"
                                HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
                                HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
                                IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
                                IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}"
                                IsTabStop="False"
                                IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}"
                                VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
                                VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
                                ZoomMode="Disabled" />
                            <ContentControl
                                x:Name="PlaceholderTextContentPresenter"
                                Grid.Row="0"
                                Grid.RowSpan="2"
                                Grid.Column="0"
                                Grid.ColumnSpan="2"
                                Margin="{TemplateBinding BorderThickness}"
                                Padding="{TemplateBinding Padding}"
                                HorizontalAlignment="Left"
                                VerticalAlignment="Center"
                                Content="{TemplateBinding PlaceholderText}"
                                Foreground="{TemplateBinding PlaceholderForegroundBrush}"
                                IsHitTestVisible="False"
                                IsTabStop="False" />

                            <Button
                                x:Name="DeleteButton"
                                Grid.Row="1"
                                Grid.Column="1"
                                MinWidth="34"
                                Margin="{ThemeResource HelperButtonThemePadding}"
                                VerticalAlignment="Stretch"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                FontSize="{TemplateBinding FontSize}"
                                Foreground="{TemplateBinding ForegroundFocusBrush}"
                                IsTabStop="False"
                                Style="{StaticResource DeleteButtonStyle}"
                                Visibility="Collapsed" />

                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HeaderContentPresenter" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledBaseLowBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement" Storyboard.TargetProperty="Background">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledTransparentBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" Storyboard.TargetProperty="Background">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlBackgroundBaseLowBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" Storyboard.TargetProperty="BorderBrush">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledBaseLowBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledChromeDisabledLowBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PlaceholderTextContentPresenter" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledChromeDisabledLowBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Normal" />

                                    <VisualState x:Name="PointerOver">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement" Storyboard.TargetProperty="Opacity">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextControlBackgroundHoverOpacity}" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Focused">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PlaceholderTextContentPresenter" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding PlaceholderForegroundFocusBrush, RelativeSource={RelativeSource TemplatedParent}}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement" Storyboard.TargetProperty="Background">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding BackgroundFocusBrush, RelativeSource={RelativeSource TemplatedParent}}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement" Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="{Binding ForegroundFocusBrush, RelativeSource={RelativeSource TemplatedParent}}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement" Storyboard.TargetProperty="RequestedTheme">
                                                <DiscreteObjectKeyFrame KeyTime="0" Value="Light" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="ButtonStates">
                                    <VisualState x:Name="ButtonVisible">
                                        <Storyboard>

                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="DeleteButton" Storyboard.TargetProperty="Visibility">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Visible</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>

                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="ButtonCollapsed" />
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    <xamanimation:StoryBoard x:Key="EntriesAnimation" Target="{x:Reference UserEntries}">
        <xamanimation:FadeToAnimation Opacity="0" Duration="0" />
        <xamanimation:FadeToAnimation Opacity="1" Duration="500" />
    </xamanimation:StoryBoard>