标签: xamlparseexception

uwp xaml 解析失败,类库 dll

我有一个非常简单的 uwp 应用程序,其中我引用了一个类库,该类库显然也是一个 uwp 项目,并且具有自定义 ContentDialog。当我直接将它作为项目引用时,它工作得很好,并且 ContentDialog 也会打开。但是,当我删除项目并使用其生成的 dll(用于调试模式的 Debug 和用于发布模式的 Release)并引用该 dll 时,我会在该 ContentDialog 的构造函数中收到 xaml Parse 异常。

UWP 客户端应用程序代码

public sealed partial class MainPage : Page
{
    private async Task Test()
    {
        var exitNode = new ExitNodeCode.ExitNode();
        await exitNode.AskForPermissionPopup();
    }

    public MainPage() => InitializeComponent();

    protected async override void OnNavigatedTo(NavigationEventArgs e)
    {
        await Test();
        base.OnNavigatedTo(e);  
    }
}
Run Code Online (Sandbox Code Playgroud)

Test()方法上抛出异常,但堆栈跟踪(用断点确认)导致该自定义 contentDialog 的构造函数中的 InitializeComponent() 方法。

类库项目中的方法

public async Task AskForPermissionPopup()
{
    var dialog = new PermissionDialog();
    await dialog.ShowAsync();                
}
Run Code Online (Sandbox Code Playgroud)

自定义内容对话框的 …

c# xaml xamlparseexception windows-runtime uwp

6
推荐指数
1
解决办法
216
查看次数

是什么导致WpfXamlLoader.TransformNodes()中的NullReferenceException?

我试图找出一个仅在发布模式下发生的问题,最有可能是由于某些属性的无效混淆引起的。我知道初始化特定控件时会发生这种情况,但是此控件非常庞大。我花了一天时间浏览所有XAML和绑定,但仍然看不到是什么导致了此异常。

有什么办法获取更多信息。要知道是什么导致了此异常?

Exception : System.NullReferenceException
Message   : Object reference not set to an instance of an object.
Source    : PresentationFramework
Help      : 
Stack     :
   at System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, Boolean onlyLoadOneNode, Boolean skipJournaledProperties, Boolean shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack`1 stack, IStyleConnector styleConnector)
   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.LoadComponent(Object component, Uri …
Run Code Online (Sandbox Code Playgroud)

wpf xaml xamlparseexception

5
推荐指数
2
解决办法
1110
查看次数

绑定到列表框时出现XamlParseException

在我的应用程序中,我允许用户将相机和照片库中的照片保存到隔离存储中.然后我获取每个文件的名称并阅读照片并添加到我的列表中.构建列表后,我将其绑定到列表框.

我可以大约5显示没有问题.滚动后我得到异常:

System.Windows.Markup.XamlParseException occurred
  Message= [Line: 0 Position: 0]
   --- Inner Exception ---
KeyNotFoundException
Run Code Online (Sandbox Code Playgroud)

这是我的XAML:

<ListBox x:Name="userPhotosListBox">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel x:Name="DataTemplateStackPanel" Orientation="Horizontal">
                <ContentControl Content="{Binding Image}" Width="400" />
                <Image Name="{Binding FileName}" Source="/Images/appbar.delete.rest.png" Width="48" Height="48"
                    MouseLeftButtonUp="Image_MouseLeftButtonUp" VerticalAlignment="Center" HorizontalAlignment="Center" MaxWidth="48" MaxHeight="48" />
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)

这是代码:

using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
    var userFiles = store.GetFileNames();
    foreach (var userFile in userFiles)
    {
        if (userFile.Contains(PhotoInIsolatedStoragePrefix))
        {
            var currentBitmap = ReadBitmapImageFromIso(userFile);
            var userPhotoImage = new Image { Source = currentBitmap };
            var userImg = …
Run Code Online (Sandbox Code Playgroud)

c# xaml xamlparseexception windows-phone-7

5
推荐指数
1
解决办法
1018
查看次数

System.Windows.Markup.XamlParseException - 方法或操作未实现

首先,使用Windows 7,x86在64位机器上构建,VS2010。

在运行我们的 CS gui 代码时,我们遇到了如下问题:

A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll

Additional information: The method or operation is not implemented.
Run Code Online (Sandbox Code Playgroud)

我进行了大量搜索,但找不到任何遇到此“附加信息”问题的人。这是我所掌握的所有信息:

  • 该项目似乎从未真正触及我们的任何代码。断点永远不会被命中。
  • 调用堆栈(我将在下面粘贴)似乎证实了这一点。这几乎就像启动时就坏了一样。
  • 问题不在我们的代码中。我们团队的一名成员可以使用 GUI,但我们不知道她的计算机上的配置有何不同。

我们都很困惑。我想向你们提供我能提供的一切信息来帮助我们——但我陷入了这样的境地:我什至不知道什么可以帮助你们帮助我。如果有人知道如何诊断这个问题 - 或者可以解释这种行为并有解决方案,我们很想知道。

调用堆栈粘贴如下:

>   PresentationFramework.dll!System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader xamlReader, System.Xaml.IXamlObjectWriterFactory writerFactory, bool skipJournaledProperties, object rootObject, System.Xaml.XamlObjectWriterSettings settings, System.Uri baseUri) + 0x170 bytes 
PresentationFramework.dll!System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader xamlReader, bool skipJournaledProperties, object rootObject, System.Xaml.Permissions.XamlAccessLevel accessLevel, System.Uri baseUri) + 0x40 bytes    
PresentationFramework.dll!System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream stream, System.Windows.Markup.ParserContext parserContext, object parent, bool closeStream) + 0x20b bytes  
PresentationFramework.dll!System.Windows.Application.LoadBamlStreamWithSyncInfo(System.IO.Stream stream, System.Windows.Markup.ParserContext pc) + 0xad …
Run Code Online (Sandbox Code Playgroud)

c# dll xamlparseexception

5
推荐指数
0
解决办法
4529
查看次数

获取"无法将类型EventTriggerBehavior的实例添加到集合BehaviorCollection"以使可单击的TextBlock

我的应用程序有一系列按钮硬编码为导航菜单,但我想将其升级为更多数据驱动的东西.

    <Button Content="MyPage">
        <i:Interaction.Behaviors>
            <core:EventTriggerBehavior EventName="Click">
                <core:NavigateToPageAction TargetPage="Namespace.MyPage"/>
            </core:EventTriggerBehavior>
        </i:Interaction.Behaviors>
    </Button>
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试将此行为放在不同的XAML元素(特别是作为数据模板的一部分的TextBlock)时,我收到以下错误.

NavMockUp.Windows.exe中出现"Windows.UI.Xaml.Markup.XamlParseException"类型的异常,但未在用户代码中处理

WinRT的信息:无法添加类型"Microsoft.Xaml.Interactions.Core.EventTriggerBehavior"的实例类型"Microsoft.Xaml.Interactivity.BehaviorCollection"的集合

    <TextBlock Text="Click for Page">
        <i:Interaction.Behaviors>
            <core:EventTriggerBehavior EventName="Click">
                <core:NavigateToPageAction TargetPage="Namespace.MyPage"/>
            </core:EventTriggerBehavior>
        </i:Interaction.Behaviors>
    </TextBlock>
Run Code Online (Sandbox Code Playgroud)

xaml behavior xamlparseexception windows-runtime winrt-xaml

5
推荐指数
1
解决办法
2164
查看次数

WTF WPF TabControl?

我相信这是WPF中的一个错误(v4.0,如果它很重要),但它已经很晚了,也许我错过了一些东西.

为了说明的目的,我绑定了一个假的例子:

    <x:Array x:Key="SampleItems" Type="sys:String">
        <sys:String>Foo</sys:String>
        <sys:String>Bar</sys:String>
        <sys:String>Baz</sys:String>
    </x:Array>
Run Code Online (Sandbox Code Playgroud)

这将工作并显示三个具有相同标题和内容的选项卡:

<TabControl ItemsSource="{StaticResource SampleItems}">
            <TabControl.ItemContainerStyle>
                <Style TargetType="TabItem">
                    <Setter Property="Header" Value="{Binding}" />
                    <Setter Property="Content" Value="{Binding}" />
                </Style>
            </TabControl.ItemContainerStyle>
        </TabControl>
Run Code Online (Sandbox Code Playgroud)

但是,这会抛出一个异常,消息"错误10指定的元素已经是另一个元素的逻辑子元素.首先断开它.":

<TabControl ItemsSource="{StaticResource SampleItems}">
    <TabControl.ItemContainerStyle>
        <Style TargetType="TabItem">
            <Setter Property="Header">
                <Setter.Value>
                    <!-- Anything here causes this problem. -->
                    <TextBlock Text="{Binding}"/>
                </Setter.Value>
            </Setter>
            <Setter Property="Content" Value="{Binding}" />
        </Style>
    </TabControl.ItemContainerStyle>
</TabControl>
Run Code Online (Sandbox Code Playgroud)

重要的是要注意,这可以与TextBlock中的任何文本重现.实际上,我可以用任何XAML替换标题TextBlock并获取此消息.我无法解释这一点.任何想法,或者这只是一个错误?

问题出现在VS设计器中,但这里也是运行时相关堆栈跟踪的一部分:

   at System.Windows.FrameworkElement.ChangeLogicalParent(DependencyObject newParent)
   at System.Windows.FrameworkElement.AddLogicalChild(Object child)
   at System.Windows.Controls.HeaderedContentControl.OnHeaderChanged(Object oldHeader, Object newHeader)
   at System.Windows.Controls.HeaderedContentControl.OnHeaderChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at …
Run Code Online (Sandbox Code Playgroud)

wpf xaml wpf-controls xamlparseexception

3
推荐指数
1
解决办法
2406
查看次数

WPF - Window 类中的单元测试方法时出现 XamlParseException

我正在尝试使用 MSTest 为MainWindow我的 WPF 应用程序中的类中的方法编写单元测试。但是,我收到以下异常:

System.Windows.Markup.XamlParseException: 'System.Windows.StaticResourceExtension' 上的提供值引发异常。行号“127”和行位置“32”。---> System.Exception: 找不到名为“verticalLineStyle”的资源。资源名称区分大小写。

verticalLineStyleResourceDictionary中包含的a中找到App.xaml。我不需要这种风格来测试我试图测试的方法,但我无法超越这一点。我只是MainWindow在我的单元测试中创建一个新实例并尝试调用实例方法。当我尝试创建MainWindow. MainWindow被定义为public partial class MainWindow : Window

我如何摆脱这个错误?在 WPF 应用程序的 windows 中是否有一些首选的单元测试方法?

c# wpf unit-testing mstest xamlparseexception

3
推荐指数
1
解决办法
1870
查看次数

窗口启动时出现xamlParseException

当我从应用程序中的另一个窗口显示此窗口时,出现以下错误:

发生XamlParseException'设置connectionId引发异常.行号"4"和行位置"25".

内部例外:

{"无法将'System.Windows.Controls.TabControl'类型的对象强制转换为'WpfApplication1.Window1'."}

我的xaml代码如下:

 <Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="482" Width="603" Loaded="Window_Loaded">
<Grid>
    <TabControl Height="402" HorizontalAlignment="Right" Margin="0,0,12,0" Name="tabControl1" VerticalAlignment="Top" Width="569" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}">
        <TabItem Header="tabItem1" Name="tabItem1">
            <Grid></Grid>
        </TabItem>
        <TabItem Header="tabItem2" Name="tabItem2">
            <Grid Height="374" Width="563">
                <ListView Height="317" HorizontalAlignment="Left" Margin="6,10,0,0" Name="listView1" VerticalAlignment="Top" Width="550">
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Header="IP" DisplayMemberBinding="{Binding CustomerIP}"/>
                            <GridViewColumn Header="Host Name" DisplayMemberBinding="{Binding HostName}"/>
                            <GridViewColumn Header="MAC" DisplayMemberBinding="{Binding MAC}"/>
                            <GridViewColumn Header="Avg. Ping Time" DisplayMemberBinding="{Binding time}"/>
                        </GridView>
                    </ListView.View>
                </ListView>
            </Grid>
        </TabItem>
        <TabItem Header="tabItem3" Name="tabItem3">
            <Grid Height="307" />
        </TabItem>
    </TabControl>
    <Button Content="Cancel" Height="23" HorizontalAlignment="Left" …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml xamlparseexception

3
推荐指数
1
解决办法
9204
查看次数

加载generic.xaml以合并资源字典时,XamlReader抛出

试图在代码中加载generic.xaml但它会抛出XamlParseException.代码如下:

Uri uri = new Uri("Themes/Generic.xaml", UriKind.Relative);
StreamResourceInfo info = Application.GetResourceStream(uri);
System.Windows.Markup.XamlReader reader = new System.Windows.Markup.XamlReader();

ResourceDictionary resdict = (ResourceDictionary)reader.LoadAsync(info.Stream);

this.Resources.MergedDictionaries.Add(resdict);
Run Code Online (Sandbox Code Playgroud)

我们的想法是在基页中合并资源字典.然后派生页面可以使用{StaticResource DarkBrush}例如来自其基类的样式,颜色,画笔等.

但上面的代码抛出:

'',十六进制值0x0C,是无效字符.第1行,第1位.

generic.xaml文件是以标准方式在VS2010中创建的.试图将Build Action设置为Resource,但这也不起作用......

我从Microsoft 获得了代码示例.它用于加载页面.任何帮助将不胜感激.

wpf generic.xaml xamlparseexception xamlreader

3
推荐指数
1
解决办法
1551
查看次数

关于外键的例外

这是内部异常:

InnerException: System.Data.UpdateException
Message=Entities in 'OrganizerDBEntities.Assignments' participate in 
the 'CourseId' relationship. 0 related 'Course' were found. 
1 'Course' is expected.`  
Run Code Online (Sandbox Code Playgroud)

我有三个表(文件夹,作业,课程).Assignment表有一个名为AssignmentId的主键和一个名为CourseId的外键,其"Allow Nulls"属性已设置为true.所以这个例外阻止我调用_entities.SaveChanges(); 从而阻止我向数据库添加数据.


更新:感谢marc,问题解决了,但另一个问题出现了:

 InnerException: System.Data.UpdateException
        Message=An error occurred while updating the entries. See the InnerException for details.
        Source=System.Data.Entity
        StackTrace:
             at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
             at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
             at System.Data.Objects.ObjectContext.SaveChanges(Boolean acceptChangesDuringSave)
             at System.Data.Objects.ObjectContext.SaveChanges()
             at AssignmentOrganizer.App_Data.AssignmentRepository.CreateAssignment(Assignment assignmentToCreate) in C:\Users\Mohit\Documents\Visual Studio 2010\Projects\AssignmentOrganizer\AssignmentOrganizer\App_Data\AssignmentRepository.cs:line 19
             at AssignmentOrganizer.MainWindow..ctor() in C:\Users\Mohit\Documents\Visual Studio 2010\Projects\AssignmentOrganizer\AssignmentOrganizer\MainWindow.xaml.cs:line 54
        InnerException: System.Data.EntityCommandCompilationException
             Message=An error occurred while preparing the command definition. See the …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework foreign-keys xamlparseexception

2
推荐指数
1
解决办法
7732
查看次数

XamlReader和Umlauts

我有一个带有德语变音符号(下面的saml)的xaml现在当我尝试解析它时,我得到一个invalidchar错误.

当我不使用XamlParser Context时,它可以工作.但我必须使用它来设置一些类型映射


XAML:

<UserControl 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"
    xmlns:test="clr-namespace:BR.UI.Tests.Items;assembly=BR.UI.ViewLocator.Tests"
    mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.DataContext>
        <test:SampleViewModel />
    </UserControl.DataContext>
    <Grid>
        <Label>ö</Label>
    </Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)

解析它的代码

 var context = new ParserContext();
 var result = System.Windows.Markup.XamlReader.Parse(xaml,context);
Run Code Online (Sandbox Code Playgroud)

我找不到任何设置编码提示(这将是.net字符串UTF-16)我做错了什么?

我还尝试使用XmlParserContext注入编码.

    var xmlcontext = new XmlParserContext(null, null, null, XmlSpace.Preserve,
                                          Encoding.Unicode);

    var context = new ParserContext(xmlcontext);
Run Code Online (Sandbox Code Playgroud)

但它没有帮助:-(

我需要做什么?有某种XAML编码吗?

c# wpf encoding xamlparseexception xamlreader

2
推荐指数
1
解决办法
803
查看次数

为什么我不能抓住这个例外?

为什么我不能抓住以下内容XamlParseException

在此输入图像描述

单击" 继续"按钮后,程序将继续执行正常操作(捕获异常并ex.Message在控制台上打印).

问题是Visual Studio异常对话框.为什么会出现?

c# exception visual-studio xamlparseexception xamlreader

1
推荐指数
1
解决办法
117
查看次数