I'm sorry if the title is a bit confused, but I don't really know how to shortly describe this issue. I have a wpf windows application that runs fine in Windows 8 and 10 but crashes on Windows 7 when loading the main interface. The exception the application was retunring was this:
Provide value on 'System.Windows.StaticResourceExtension' threw an exception. StackTrace : at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri) at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri) at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream) at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc) at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties) at System.Windows.Application.DoStartup() at System.Windows.Application.<.ctor>b__1(Object unused) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
Google told me that the issue may be the order in which I defined some static resources (Provide value on 'System.Windows.StaticResourceExtension) in my xaml file. Actually I have some DataTemplate defined as static resources in the Window.Resources tag, but as that post said, they are defined in the right order and the Window.Resources tag is the first child of the Window tag:
<Window x:Class="FlyMasterSyncGui.Forms.FlightLog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:FlyMasterSyncGui.Forms"
xmlns:formsUtils="clr-namespace:FlyMasterSyncGui.FormsUtils"
Title="FlymasterSync" Height="372" Width="608"
Icon="../Assets/icon.ico"
WindowStartupLocation="CenterScreen"
Closed="FlightLog_OnClosed"
Closing="FlightLog_OnClosing" Loaded="FlightLog_OnLoaded">
<Window.Resources>
<CollectionViewSource x:Key="groupedFlights" Source="{Binding TracksDb.Entries}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="FlightInfo.Date" Converter="{formsUtils:YearConverter}" />
<PropertyGroupDescription PropertyName="FlightInfo.Date" Converter="{formsUtils:MonthConverter}" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
<DataTemplate x:Key="InnerTemplate">
<Grid Margin="0,10,0,0">
<Border VerticalAlignment="Bottom" Background="#FF9CA7B4"
Padding="5,0,0,0">
[...]
Though, in this xaml I'm using some ValueConverters and after some attempts I found out that it is the MonthConverter that is firing the exception. The converter code is the following:
public class MonthConverter : MarkupExtension, IValueConverter
{
private MonthConverter _converter;
public MonthConverter()
{
}
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
DateTime d = (DateTime)value;
//Exception Here
var monthName = CultureInfo.GetCultureInfo("en-en").DateTimeFormat.GetMonthName(d.Month);
return char.ToUpper(monthName[0]) + monthName.Substring(1);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
if (_converter == null) _converter = new MonthConverter();
return _converter;
}
}
The exception is called when I call:
CultureInfo.GetCultureInfo("en-en").DateTimeFormat.GetMonthName(d.Month);
And I don't really understand why. At the moment I just made a custom function that converts the month number into its name, so I don't need to call CultureInfo and I fixed the problem, but I'd like to know why this exception is fired and why it only happens on Windows 7. Is xaml parsed differently in Windows 7? Is the CultureInfo data loaded later on Window 7?
Thanks in advance for any reply :)