本文介绍了XAML解析异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的XAML页面,当将其作为Visual Studio中任何应用程序的一部分加载时,可以正常加载.但是,当我使用ClickOnce部署此应用程序时,出现以下异常:
I have a simple XAML page that load fine when it is loaded as part of any application within Visual Studio. However, when I deploy this application using ClickOnce, I get the following exception:
Type : System.Windows.Markup.XamlParseException, PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Message : Unable to cast object of type 'System.Windows.Controls.Grid' to type 'EMS.Controls.Dictionary.StatusBarControl'. Error at object 'System.Windows.Controls.Grid' in markup file 'EMS.Controls.Dictionary;component/views/statusbarcontrol.xaml'.
Source : PresentationFramework
Help link :
LineNumber : 0
LinePosition : 0
KeyContext :
UidContext :
NameContext :
BaseUri : pack://application:,,,/EMS.Controls.Dictionary;component/views/statusbarcontrol.xaml
Data : System.Collections.ListDictionaryInternal
TargetSite : Void ThrowException(System.String, System.Exception, Int32, Int32, System.Uri, System.Windows.Markup.XamlObjectIds, System.Windows.Markup.XamlObjectIds, System.Type)
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.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.LoadComponent(Object component, Uri resourceLocator)
at EMS.Controls.Dictionary.StatusBarControl.InitializeComponent()
at EMS.Controls.Dictionary.StatusBarControl..ctor(IDataView content)
at OCC600.ReportManager.ReportPresenter.ShowQueryView(Object arg, Boolean bringForward, Type selectedDataType)
at OCC600.ReportManager.ReportPresenter..ctor(IUnityContainer container)
at OCC600.ReportManager.Module.Initialize()
at Microsoft.Practices.Composite.Modularity.ModuleLoader.Initialize(ModuleInfo[] moduleInfos)
Inner Exception
---------------
Type : System.InvalidCastException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Unable to cast object of type 'System.Windows.Controls.Grid' to type 'EMS.Controls.Dictionary.StatusBarControl'.
Source : EMS.Controls.Dictionary
Help link :
Data : System.Collections.ListDictionaryInternal
TargetSite : Void System.Windows.Markup.IComponentConnector.Connect(Int32, System.Object)
Stack Trace : at EMS.Controls.Dictionary.StatusBarControl.System.Windows.Markup.IComponentConnector.Connect(Int32 connectionId, Object target)
at System.Windows.Markup.BamlRecordReader.ReadConnectionId(BamlConnectionIdRecord bamlConnectionIdRecord)
at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)
XAML页面如下:
<cdic:ResultSetControl
x:Class="EMS.Controls.Dictionary.StatusBarControl"
xmlns:dc="clr-namespace:DevComponents.WpfRibbon;assembly=DevComponents.WpfRibbon"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cdic="clr-namespace:EMS.Controls.Dictionary.Primitives"
xmlns:dicutil="clr-namespace:OCC600.Infrastructure.Dictionary.Utility;assembly=EMS.Infrastructure.Dictionary"
Loaded="ResultSetControl_Loaded">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Resources/Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
<BooleanToVisibilityConverter x:Key="BooToVisConv"/>
</ResourceDictionary>
</UserControl.Resources>
<Grid Name="panel" >
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="21"/>
</Grid.RowDefinitions>
<StatusBar Name="statusBar" Grid.Row="1">
<StatusBar.ItemsPanel>
<ItemsPanelTemplate>
<DockPanel LastChildFill="False"/>
</ItemsPanelTemplate>
</StatusBar.ItemsPanel>
<StatusBarItem Margin="10,0, 10, 0">
<TextBlock Text="{Binding CountText}" Padding="5,0"/>
</StatusBarItem>
<StatusBarItem Margin="10,0">
<TextBlock Text="{Binding MemoryUsageText}" Padding="5,0"/>
</StatusBarItem>
<StatusBarItem Margin="10,0" MaxWidth="400">
<TextBlock Text="{Binding StatusReport.Summary}" Padding="5,0" />
</StatusBarItem>
<ProgressBar Margin="20,0" Name="progBar" Width="150" Height="13" Visibility="Collapsed" >
<ProgressBar.ContextMenu>
<ContextMenu Name="ctxMenu" ItemsSource="{Binding ActiveWorkItems}"
Visibility="{Binding Path=ActiveWorkItems.HasItems, Converter={StaticResource BooToVisConv}}">
<ContextMenu.ItemContainerStyle>
<Style TargetType="{x:Type MenuItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type MenuItem}">
<StackPanel Height="20" Margin="10,0" Orientation="Horizontal" HorizontalAlignment="Left">
<TextBlock Text="{Binding Path=Name, Mode=OneTime}"
Foreground="Black" VerticalAlignment="Center" HorizontalAlignment="Left" />
<ToggleButton Style="{StaticResource vistaGoldenToggleButtonStyle}"
Padding="5,0" Content="Cancel" IsChecked="{Binding Cancel}"
Margin="10,0,0,0" >
</ToggleButton>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ContextMenu.ItemContainerStyle>
</ContextMenu>
</ProgressBar.ContextMenu>
</ProgressBar>
<StatusBarItem Margin="10,0" MaxWidth="400" HorizontalAlignment="Right">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Last Update:" Padding="5,0" />
<TextBlock Text="{Binding TimeStamp}" Padding="5,0" />
</StackPanel>
</StatusBarItem>
<!-- TODO: Put checkmark if all is well, or error if connection failed-->
<StatusBarItem Style="{DynamicResource {ComponentResourceKey
TypeInTargetAssembly=dc:Ribbon, ResourceId=StatusBarItemAlt}}"
DockPanel.Dock="Right" Padding="6,0,32,0" >
<cdic:SplitButton Margin="5,0" Padding="5,2"
Style="{DynamicResource {ComponentResourceKey
TypeInTargetAssembly={x:Type cdic:SplitButtonResources}, ResourceId=vistaSplitButtonStyle}}"
Mode="Split">
<cdic:SplitButton.ContextMenu>
<ContextMenu >
<MenuItem Header="Refresh Now" Command="{Binding ToggleConnectivityCmd}"
CommandParameter="false"/>
<MenuItem IsCheckable="True"
IsChecked="{Binding ConnectState, Converter={StaticResource isFailedConverter}}"
CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self},
Path=IsChecked}"
Header="Work Offline" Command="{Binding ToggleConnectivityCmd}"/>
</ContextMenu>
</cdic:SplitButton.ContextMenu>
<cdic:SplitButton.Content>
<StackPanel Orientation="Horizontal">
<Image
x:Name="img"
Source="{Binding ConnectState, Converter={StaticResource imageConverter}}"
Width="16" Height="16" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Text="{Binding ConnectState}" Padding="3,0,0,0"/>
</StackPanel>
</cdic:SplitButton.Content>
</cdic:SplitButton>
</StatusBarItem>
</StatusBar>
</Grid>
</cdic:ResultSetControl>
错误似乎无处不在.有什么想法吗?
The error just seems to have come out of no where. Any ideas?
TIA.
推荐答案
我的猜测是,对"EMS.Controls.Dictionary.StatusBarControl"控件的引用是应该在用户GAC中安装的库的一部分.确保您没有缺少应用程序先决条件.
My guess would be that the reference "EMS.Controls.Dictionary.StatusBarControl" control is part of a library that should be installed in the users GAC. Make sure you're not missing an application prerequisite.
这篇关于XAML解析异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!