Hi,
when starting-up my WPF application a splash screen in a separate thread is shown. Calling 'splash.Show()' (see code below) sometimes causes a NullReferenceException (see stack trace below). This NRE exception appears right after reboot of windows machine, at the first attempt to start the WPF application. All following application start-ups are successful.
The splash screen window is defined by Xaml using MVVM pattern.
Can anybody explain this behavior? Is this a Binding problem?
Code running in separate thread:
public static void RunSplashScreenInSeparateThread()
{
var splash = new MarsSplashScreen();
mSplashIsOn = true;
splash.Show();
splash.SetUpProgress(0, 20);
mSplashScreen = splash;
mSplashDispatcher = splash.Dispatcher;
splash.Closed += (sender2, e2) => splash.Dispatcher.InvokeShutdown();
if (!mSplashIsClosed) // check whether bootstrapper start-up succeeded. If not, dispatcher shall not run
Dispatcher.Run();
}
Stacktrace of NRE:
2013-08-16 15:43:17.3750 | ERROR | (8) | MarsApplication | Object reference not set to an instance of an object. | System.NullReferenceException: Object reference not set to an instance of an object.
at MS.Internal.AssemblyHelper.IsXLinqCollectionPropertyImpl(PropertyDescriptor pd)
at MS.Internal.AssemblyHelper.IsXLinqCollectionProperty(PropertyDescriptor pd)
at MS.Internal.Data.ValueTable.ShouldCache(Object item, PropertyDescriptor pd)
at MS.Internal.Data.DataBindEngine.RegisterForCacheChanges(Object item, Object descriptor)
at MS.Internal.Data.PropertyPathWorker.ReplaceItem(Int32 k, Object newO, Object parent)
at MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(Int32 k, ICollectionView collectionView, Object newValue, Boolean isASubPropertyChange)
at MS.Internal.Data.ClrBindingWorker.AttachDataItem()
at System.Windows.Data.BindingExpression.Activate(Object item)
at System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt attempt)
at System.Windows.Data.BindingExpression.AttachOverride(DependencyObject target, DependencyProperty dp)
at System.Windows.Data.BindingExpressionBase.Attach(DependencyObject target, DependencyProperty dp)
at System.Windows.Data.BindingExpressionBase.OnAttach(DependencyObject d, DependencyProperty dp)
at System.Windows.StyleHelper.GetInstanceValue(UncommonField`1 dataField, DependencyObject container, FrameworkElement feChild, FrameworkContentElement fceChild, Int32 childIndex, DependencyProperty dp, Int32 i, EffectiveValueEntry& entry)
at System.Windows.StyleHelper.GetChildValueHelper(UncommonField`1 dataField, ItemStructList`1& valueLookupList, DependencyProperty dp, DependencyObject container, FrameworkObject child, Int32 childIndex, Boolean styleLookup, EffectiveValueEntry&
entry, ValueLookupType& sourceType, FrameworkElementFactory templateRoot)
at System.Windows.StyleHelper.GetChildValue(UncommonField`1 dataField, DependencyObject container, Int32 childIndex, FrameworkObject child, DependencyProperty dp, FrugalStructList`1& childRecordFromChildIndex, EffectiveValueEntry& entry,
ValueLookupType& sourceType, FrameworkElementFactory templateRoot)
at System.Windows.StyleHelper.GetValueFromTemplatedParent(DependencyObject container, Int32 childIndex, FrameworkObject child, DependencyProperty dp, FrugalStructList`1& childRecordFromChildIndex, FrameworkElementFactory templateRoot, EffectiveValueEntry&
entry)
at System.Windows.StyleHelper.ApplyTemplatedParentValue(DependencyObject container, FrameworkObject child, Int32 childIndex, FrugalStructList`1& childRecordFromChildIndex, DependencyProperty dp, FrameworkElementFactory templateRoot)
at System.Windows.StyleHelper.InvalidatePropertiesOnTemplateNode(DependencyObject container, FrameworkObject child, Int32 childIndex, FrugalStructList`1& childRecordFromChildIndex, Boolean isDetach, FrameworkElementFactory templateRoot)
at System.Windows.FrameworkTemplate.InvalidatePropertiesOnTemplate(DependencyObject container, Object currentObject)
at System.Windows.FrameworkTemplate.HandleBeforeProperties(Object createdObject, DependencyObject& rootObject, DependencyObject container, FrameworkElement feContainer, INameScope nameScope)
at System.Windows.FrameworkTemplate.<>c__DisplayClass6.<LoadOptimizedTemplateContent>b__3(Object sender, XamlObjectEventArgs args)
at System.Xaml.XamlObjectWriter.OnBeforeProperties(Object value)
at System.Xaml.XamlObjectWriter.Logic_CreateAndAssignToParentStart(ObjectWriterContext ctx)
at System.Xaml.XamlObjectWriter.WriteStartMember(XamlMember property)
at System.Xaml.XamlWriter.WriteNode(XamlReader reader)
at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)
at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlObjectWriter objectWriter)
at System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField)
at System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List`1 affectedChildren)
at System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate)
at System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1 templateDataField, FrameworkElement container)
at System.Windows.FrameworkElement.ApplyTemplate()
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.GridViewRowPresenter.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.Border.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.Control.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.UIElement.UpdateLayout()
at System.Windows.Interop.HwndSource.SetLayoutSize()
at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
at System.Windows.Interop.HwndSource.set_RootVisual(Visual value)
at System.Windows.Window.SetRootVisual()
at System.Windows.Window.SetRootVisualAndUpdateSTC()
at System.Windows.Window.SetupInitialState(Double requestedTop, Double requestedLeft, Double requestedWidth, Double requestedHeight)
at System.Windows.Window.CreateSourceWindow(Boolean duringShow)
at System.Windows.Window.CreateSourceWindowDuringShow()
at System.Windows.Window.SafeCreateWindowDuringShow()
at System.Windows.Window.ShowHelper(Object booleanBox)
at System.Windows.Window.Show()
at RohdeSchwarz.API.Bootstrapper.Graphical.DynamicSplashScreen.RunSplashScreenInSeparateThread()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Xaml of splash screen (The image in this Xaml is of type 'svg' and it is not posted due to confidential matter):
<GraphicalShell:DynamicSplashScreen x:Class="RohdeSchwarz.API.Bootstrapper.Graphical.MarsSplashScreen"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
xmlns:svg="http://sharpvectors.codeplex.com/runtime/"
xmlns:GraphicalShell="clr-namespace:RohdeSchwarz.API.Bootstrapper.Graphical"
x:Name="MarsSplashScreenControl"
Width="640" Height="480" Background="White">
<Border BorderBrush="Black" BorderThickness="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="85" />
<RowDefinition Height="*" />
<RowDefinition Height="40" />
</Grid.RowDefinitions>
<Image Grid.Row="0" Source="Icons/CMWtoolsSplashBanner.png" Height="85" />
<Grid Grid.Row="1" Margin="18,5,18,5">
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding ApplicationName}" FontFamily="Arial" FontSize="26" FontWeight="Bold"
VerticalAlignment="Center" />
<TextBlock Grid.Column="1" Text="{Binding ApplicationVersion, StringFormat=' V\{0\}'}" FontFamily="Arial"
FontSize="26" FontWeight="Bold" VerticalAlignment="Center" />
</Grid>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="230" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Image ... >
</Grid>
<Grid Grid.Column="1" Margin="10,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="*" />
<RowDefinition Height="22" />
</Grid.RowDefinitions>
<TextBlock Text="Plug-ins" FontSize="16" FontFamily="Arial" VerticalAlignment="Center" />
<ListView Grid.Row="1" ItemsSource="{Binding Features}">
<ListView.Style>
<Style TargetType="{x:Type ListView}">
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Foreground" Value="Black" />
</Style>
</ListView.Style>
<ListView.Resources>
<Style x:Key="ListViewWithoutHeaderStyle" TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Visibility" Value="Collapsed" />
</Style>
</ListView.Resources>
<ListView.View>
<GridView x:Name="GridViewFeatures" ColumnHeaderContainerStyle="{StaticResource ListViewWithoutHeaderStyle}">
<GridViewColumn Header="Id" Width="140">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Id}" FontSize="16" FontFamily="Arial" FontWeight="Bold"
VerticalAlignment="Center" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Name" Width="110">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" FontSize="16" FontFamily="Arial" FontWeight="Bold"
VerticalAlignment="Center" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Version" Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Version}" FontSize="16" FontFamily="Arial" FontWeight="Bold"
VerticalAlignment="Center" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<TextBlock Grid.Row="2" Text="Copyright © 2013 Rohde & Schwarz. All rights reserved." FontFamily="Arial"
FontSize="12" HorizontalAlignment="Right" VerticalAlignment="Bottom" />
</Grid>
</Grid>
</Grid>
<Grid Grid.Row="2" Background="#FFDFE1E5">
<Grid Grid.Row="1" VerticalAlignment="Center" Margin="18,0,18,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" x:Name="ProgressMessageControl" Text="Loading..." FontSize="12" FontFamily="Arial"
VerticalAlignment="Center" />
<ProgressBar Grid.Column="1" x:Name="ProgressBarControl" Height="16" Margin="10,0,0,0" VerticalAlignment="Center" />
</Grid>
</Grid>
</Grid>
</Border>
</GraphicalShell:DynamicSplashScreen>
Any help would be appreciated a lot!