.NET 4 用の WPF アプリケーションを開発しています。
ある日、クライアントは、新しいリリースが自分の Windows 7 マシンで動作しない (起動時にアプリケーションが終了する) と私に言い、Windows イベント ビューアーで例外ログを見つけました。
Application: myapp.exe Framework Version: v4.0.30319 Description:
The process was terminated due to an unhandled exception. Exception Info: System.Windows.Markup.XamlParseException
Stack: at System.Windows.Markup.XamlReader.RewrapException(System.Exception, System.Xaml.IXamlLineInfo, System.Uri)
at System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri)
at System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows.Markup.ParserContext, System.Object, Boolean)
at System.Windows.Application.LoadBamlStreamWithSyncInfo(System.IO.Stream, System.Windows.Markup.ParserContext)
at ... (I guess no point to continue...)
この問題は、私も他の開発者も私たちのマシンで再現できないため、私を夢中にさせています.VirtualBoxのクリーンなWindows 7インストールでも再現できません.
クライアントのアプリケーションを壊した変更を見つけようとしたとき、問題のある部分を見つけました. 違いは次のとおりです。
これはうまくいきます:
<ComboBox x:Name="comboBoxZoom" Margin="130,10,0,0" HorizontalAlignment="Left" Width="40" FontFamily="Arial" FontSize="12" VerticalAlignment="Top" TabIndex="1" Panel.ZIndex="2" />
これは壊れます:
<ComboBox x:Name="comboBoxZoom" Style="{StaticResource comboBoxStyle}" Margin="130,10,0,0" HorizontalAlignment="Left" Width="40" FontFamily="Arial" FontSize="12" VerticalAlignment="Top" TabIndex="1" Panel.ZIndex="2" />
本質的な違いは
Style="{StaticResource comboBoxStyle}"
しかし、このスタイルは以前にアプリケーションの他の部分で問題なく使用されていました! この例外を引き起こす同じファイルには、他の多くの Style="{StaticResource someotherstyle}" が含まれており、クライアント マシンで正常に動作します。
これらのスタイルはすべて、1 つのファイル ControlStyles.xaml にあります。omboBoxStyle は、いくつかの Web サイトからコピーされた、次のような変更されたスタイルです 。
Style="{StaticResourceomboBoxStyle}" によって一部の特定のマシンでのみアプリがクラッシュするのはなぜですか? また、このバグを修正する方法を教えてください。