Reputation: 13733
We are developing a WPF application for .NET 4.
One day the client told me that the new release does not work (application just quits upon startup) on his Windows 7 machine and he found the exception log in the Windows Event Viewer:
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...)
This problem is driving me crazy because nor me nor another developer cannot reproduce it on our machines, and we cannot reproduce it even on a clean Windows 7 install in VirtualBox.
When we tried to find the changes which broke the application for the client, we found the offending piece. Here is the difference:
This works fine:
<ComboBox x:Name="comboBoxZoom" Margin="130,10,0,0" HorizontalAlignment="Left" Width="40" FontFamily="Arial" FontSize="12" VerticalAlignment="Top" TabIndex="1" Panel.ZIndex="2" />
This breaks:
<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" />
Essentially the difference is only
Style="{StaticResource comboBoxStyle}"
but ths style has been used in other parts of our application before without any issues! And the same file which causes this exception, contains many other Style="{StaticResource someotherstyle}" and they work fine on the client machine.
All these styles are located in one file ControlStyles.xaml. The comboBoxStyle is a modified style copied from some website, similar to this one: http://social.msdn.microsoft.com/Forums/nl/wpf/thread/53134b87-1a99-4998-a1fb-b3d8a9bd2773
Why does Style="{StaticResource comboBoxStyle}" make my app crash only on some certain machines and how to fix this bug?
Upvotes: 2
Views: 1271
Reputation: 21
I had the same problem and after pulling my hair out for two days, I figured the solution using Windbg with the help of someone in the C# IRC channel.
So in my case, the exception was thrown because I hadn't set the type attribute for app.config's trace listeners, and it had nothing to do with XAML, although oddly enough when I removed the combobox binding in my XAML, I could run the program in release mode, but the real solution lied in the app.config. I could run the program fine in debug mode though. This sounds like a nasty bug with the compiler.
So look for possible oversights in your app.config, if everything seems right there, then just grab Windbg and debug it on your own until you find the root cause of the exception.
Upvotes: 1