I have small WPF tool with simple XAML form (see below) which uses no 3rd-party libraries or controls. It is running without issues on 50 machines from Windows XP to Windows 8.1 in .net 3.5
When I launch it on Windows Server 2012, it runs well (writes files, displays MessageBoxes) until the execution advances to first WPF form, where it crashes in non-user code loading a (visual theme) library during XAML parsing.
Are there any known .NET issues with Windows Server 2012 visual themes?
DispatcherUnhandledException:
System.Windows.Markup.XamlParseException: Failed object initialization (ISupportInitialize.EndInit).
A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)
Error at object 'ButtonRun' in markup file 'FIS;component/windows/mainwindow.xaml'. ---> System.IO.FileLoadException: A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at System.Windows.SystemResources.ResourceDictionaries.LoadExternalAssembly(Boolean classic, Boolean generic, Assembly& assembly, String& assemblyName)
at System.Windows.SystemResources.ResourceDictionaries.LoadThemedDictionary(Boolean isTraceEnabled)
at System.Windows.SystemResources.FindDictionaryResource(Object key, Type typeKey, ResourceKey resourceKey, Boolean isTraceEnabled, Boolean allowDeferredResourceReference, Boolean mustReturnDeferredResourceReference, Boolean& canCache)
at System.Windows.SystemResources.FindResourceInternal(Object key, Boolean allowDeferredResourceReference, Boolean mustReturnDeferredResourceReference)
at System.Windows.SystemResources.FindThemeStyle(DependencyObjectType key)
at System.Windows.StyleHelper.GetThemeStyle(FrameworkElement fe, FrameworkContentElement fce)
at System.Windows.FrameworkElement.UpdateThemeStyleProperty()
at System.Windows.FrameworkElement.OnInitialized(EventArgs e)
at System.Windows.FrameworkElement.TryFireInitialized()
at System.Windows.FrameworkElement.EndInit()
at System.Windows.Markup.BamlRecordReader.ElementEndInit(Object& element)
--- End of inner exception stack trace ---
at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)
at System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext, Int32 lineNumber, Int32 linePosition, String message, Exception innerException)
at System.Windows.Markup.BamlRecordReader.ThrowExceptionWithLine(String message, Exception innerException)
at System.Windows.Markup.BamlRecordReader.CreateInstanceFromType(Type type, Int16 typeId, Boolean throwOnFail)
at System.Windows.Markup.BamlRecordReader.GetElementAndFlags(BamlElementStartRecord bamlElementStartRecord, Object& element, ReaderFlags& flags, Type& delayCreatedType, Int16& delayCreatedTypeId)
at System.Windows.Markup.BamlRecordReader.BaseReadElementStartRecord(BamlElementStartRecord bamlElementRecord)
at System.Windows.Markup.BamlRecordReader.ReadElementStartRecord(BamlElementStartRecord bamlElementRecord)
at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)
at System.Windows.Markup.BamlRecordReader.Read(Boolean singleRecord)
at System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment()
at System.Windows.Markup.TreeBuilder.Parse()
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__0(Object unused)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
Simple XAML form including WPF Splash Screen (fading out) on application startup:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="MainWin" Title="..........." Height="228" Width="525" WindowStartupLocation="CenterScreen" AllowsTransparency="True" WindowStyle="None" ResizeMode="CanMinimize" MouseLeftButtonDown="Window_MouseLeftButtonDown" MouseRightButtonDown="Window_MouseRightButtonDown" Loaded="Window_Loaded">
<Window.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="MainWin"
Storyboard.TargetProperty="(Window.Opacity)"
From="0" To="1" Duration="0:0:0.5" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Window.Triggers>
<Window.Background>
<LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
<GradientStop Color="#CF767676" Offset="1"/>
<GradientStop Color="#CF565656" Offset="0.5"/>
<GradientStop Color="#CFB4B4B4"/>
</LinearGradientBrush>
</Window.Background>
<Grid>
<Image HorizontalAlignment="Center" Height="128" Margin="197.88,80.702,199.12,0" VerticalAlignment="Top" Width="128" Source="xxxxxxxxxx_128x128_png.png" Stretch="None" RenderTransformOrigin="0.575,0.541"/>
<Button x:Name="ButtonRun" Content="......." HorizontalAlignment="Left" Margin="197.88,195.04,0,0" VerticalAlignment="Top" Width="129" Height="23" IsDefault="True"/>
<Button x:Name="ButtonRunMenu" Content="....................." HorizontalAlignment="Left" Margin="377,195.04,0,0" VerticalAlignment="Top" Width="129" Height="23" IsDefault="True"/>
<Button x:Name="ButtonMinimize" Content="0" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" HorizontalAlignment="Left" Margin="462,10,0,0" VerticalAlignment="Top" Width="24" Click="ButtonMinimize_Click" BorderThickness="0" Background="#00DDDDDD" Foreground="#FFEEEEEE" FontFamily="Marlett" FontSize="16" ToolTip="............."/>
<Button x:Name="ButtonClose" Content="r" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" HorizontalAlignment="Left" Margin="491,10,0,0" VerticalAlignment="Top" Width="24" Click="ButtonClose_Click" IsCancel="True" BorderThickness="0" Background="#00DDDDDD" Foreground="#FFEEEEEE" FontFamily="Marlett" FontSize="16" ToolTip=".............."/>
<Label x:Name="LabelAppName" Content="..." Margin="67.834,17.757,0,0" VerticalAlignment="Top" HorizontalContentAlignment="Center" Foreground="#FFEEEEEE" FontSize="20" HorizontalAlignment="Left" Width="389.166"/>
<Label x:Name="LabelCurrentAction" Content="........................." HorizontalAlignment="Left" Margin="10,192.04,0,0" VerticalAlignment="Top" Foreground="#FFEEEEEE" Width="253.993"/>
<Label x:Name="LabelPreparedVersion" Content="......" HorizontalAlignment="Center" Margin="10,47.779,10,0" VerticalAlignment="Top" Width="505" HorizontalContentAlignment="Center" Foreground="#FFEEEEEE"/>
<Label x:Name="LabelErrorCondition" Content="............" HorizontalAlignment="Left" Height="26.261" Margin="0,60,0,0" VerticalAlignment="Top" Width="168" Background="#FFBB0000" Foreground="White"/>
<Label x:Name="LabelWarningCondition" Content="..........." HorizontalAlignment="Left" Height="26.261" Margin="0,90,0,0" VerticalAlignment="Top" Width="168" Background="#FFDD8800"/>
<Label x:Name="LabelNotAtLatestVersion" Content="........................" HorizontalAlignment="Left" Height="26.261" Margin="0,120,0,0" VerticalAlignment="Top" Width="168" Background="#FFCCCC00"/>
<Label x:Name="LabelUpdatesNoConnection" Content=".................................." HorizontalAlignment="Left" Height="26.261" Margin="0,150,0,0" VerticalAlignment="Top" Width="208" Background="#FFDD8800"/>
<Label x:Name="LabelUpdatesMisconfigured" Content="................................" HorizontalAlignment="Left" Height="26.261" Margin="0,150,0,0" VerticalAlignment="Top" Width="192.88" Background="#FFDD8800"/>
<Label x:Name="LabelUpdatesDisabled" Content="............................" HorizontalAlignment="Left" Height="26.261" Margin="0,150,0,0" VerticalAlignment="Top" Width="168" Background="#FFCCCCCC"/>
<Label x:Name="LabelUpdateAvailableForDownload" Content="............................" HorizontalAlignment="Left" Height="26.261" Margin="0,150,0,0" VerticalAlignment="Top" Width="168" Background="White"/>
</Grid>
</Window>
More details:
If built in Debug
configuration, it also gives info that error is on Line 26, Column 156
of the above XAML, but there is only IsDefault="True"
.
When I remove all <Button>
tags, it crashes in the same way on first <Label>
tag.
If I build new WPF app with label and a button, it runs on the same PC without crashing.
I reinstalled .NET 3.5 on the machine (by removing from system "features" and re-adding it) but no change.
Why .NET is crashing on its own stuff?
When I checked Solution explorer tool window, namely list of project references and inspected properties of each reference (in Properties window), I found that there was referenced ZIP DLL library, which had property Strong Name set to False
.
The question remains why this crashes on WPF initialization, but I guess there are 2 reasons:
on loading of first WPF control WPF scans (even unrelated) project libraries using Reflection to find whether they contain skins for WPF controls
Windows Server has set more strict policy for strong assembly names than standard Windows machines
Taking these facts together, it is understandable why library without strong name causes crash during WPF initialization only on Windows Server 2012.
User contributions licensed under CC BY-SA 3.0