Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是什么导致WPF应用程序中出现XamlParseException?_C#_.net_Wpf_Xaml_Xamlparseexception - Fatal编程技术网

C# 是什么导致WPF应用程序中出现XamlParseException?

C# 是什么导致WPF应用程序中出现XamlParseException?,c#,.net,wpf,xaml,xamlparseexception,C#,.net,Wpf,Xaml,Xamlparseexception,更新:controls.Resources.dll的加载发生在故障点之后(在两个应用程序中),因此这很可能是一个麻烦 我有两个应用程序,一个运行良好,另一个不会出现各种异常。它们是运行在.NET3.5和Windows7下的WPF应用程序。它们都是在同一组引用/依赖项上构建的。它们基本上是相同的程序。我已经手动比较了它们的主要文件,以搜索问题的来源,但没有结果 问题发生在启动过程中。异常始终是XamlParseException,但原因(从SQL异常到多点触摸异常)不同。直接堆栈是: Unable

更新:controls.Resources.dll的加载发生在故障点之后(在两个应用程序中),因此这很可能是一个麻烦

我有两个应用程序,一个运行良好,另一个不会出现各种异常。它们是运行在.NET3.5和Windows7下的WPF应用程序。它们都是在同一组引用/依赖项上构建的。它们基本上是相同的程序。我已经手动比较了它们的主要文件,以搜索问题的来源,但没有结果

问题发生在启动过程中。异常始终是XamlParseException,但原因(从SQL异常到多点触摸异常)不同。直接堆栈是:

Unable to cast object of type 'System.Windows.Controls.ListView' to type 'Lightning.Controls.Configuration.MaterialsImportExportControl'.  

Error at object 'System.Windows.Controls.ListView' in markup file 'Lightning.UI.Controls;component/configuration/materials/xaml/materialsimportexportcontrol.xaml'. 
---> System.InvalidCastException:
Unable to cast object of type 'System.Windows.Controls.ListView' 
to type 'Lightning.Controls.Configuration.MaterialsImportExportControl'.
   at Lightning.Controls.Configuration.MaterialsImportExportControl.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)
   --- 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.LoadComponent(Object component, Uri resourceLocator)
   at EndeavorUI.EndeavorPartIdWindow.InitializeComponent()
   at EndeavorUI.EndeavorPartIdWindow..ctor()
   at EndeavorUI.SystemBootUpWindow.WaitToCollapseWindow(Object sender, RoutedEventArgs e)
根据我在这里和其他地方的阅读,这实际上可能是由于未正确加载资源DLL或资源冲突造成的

我已经运行了Process Explorer,并注意到在工作程序中的.NET程序集选项卡中,存在多个非工作程序中不存在的Controls.resources.dll文件条目

我认为那些DLL也应该加载到非工作程序中;有人知道为什么他们不会这样吗

编辑以添加:以下是它试图处理的xaml文件的编辑版本:

    <controls:UserControlMultiTouchEnabled x:Class="Lightning.Controls.Configuration.MaterialsImportExportControl"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:configuration="clr-namespace:Lightning.Controls.Configuration"
        xmlns:KB="clr-namespace:Lightning.UI.Controls.KeyBoard"
        xmlns:controls="clr-namespace:Lightning.Controls"
    Loaded="LoadedHandler">
        <controls:UserControlMultiTouchEnabled.Resources>
            <controls:ConverterBooleanInverter x:Key="converterBooleanInverter" />
            <controls:MultiConverterObjectReferenceToVisibilityAndBooleanGeneralized x:Key="converterObjectRefAndBooleanToVisibility" />
            <controls:MultiConverterObjectReferenceToVisibilityAndBooleanGeneralized InvertBooleans="True" x:Key="converterObjectRefAndBooleanToVisibilityInvertBooleans" />
            <controls:ConverterObjectReferenceToVisibilityGeneralized x:Key="converterObjectRefToVisibility" />
            <controls:ConverterObjectReferenceToVisibilityGeneralized Invert="True" x:Key="converterObjectRefToVisibilityInverted" />
            <controls:ConverterBooleanToVisibilityGeneralized x:Key="converterBoolToVisibility" />
            <controls:ConverterBooleanToVisibilityGeneralized Invert="True" x:Key="converterBoolToVisibilityInverted" />
            <controls:ConverterBooleanToSelectionModeGeneralized x:Key="converterSelectionMode" />
            <controls:MultiConverterImportedMaterialDisplayInfoPropertiesToBooleanEnabled x:Key="enabledConverter" />
            <controls:MultiConverterImportedMaterialDisplayInfoPropertiesToVisibility x:Key="converterIMDIVisibility" />
            <controls:MultiConverterImportedMaterialDisplayInfoPropertiesToVisibility Invert="True" x:Key="converterIMDIVisibilityInverted" />
            <sys:String x:Key="LocStrings">Configuration.Materials.resx.MaterialsInternationalizedStrings</sys:String>
            <sys:String x:Key="AssemblyName">Lightning.UI.Controls</sys:String>

            <Style TargetType="{x:Type TextBox}">
                <Setter Property="VerticalContentAlignment" Value="Center" />
                <Style.Triggers>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Opacity" Value="0.5"/>
                    </Trigger>
                </Style.Triggers>
            </Style>

            <Style TargetType="{x:Type GroupBox}" BasedOn="{StaticResource {x:Type GroupBox}}">
                <Style.Triggers>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Opacity" Value="0.5"/>
                    </Trigger>
                </Style.Triggers>
            </Style>

            <Style TargetType="{x:Type Label}">
                <Style.Triggers>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Opacity" Value="0.5"/>
                    </Trigger>
                </Style.Triggers>
            </Style>

            <LinearGradientBrush x:Key="SelectedBackgroundBrush" EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FFE1E0E8" Offset="0"/>
                <GradientStop Color="#FFA2A4A4" Offset="1"/>
                <GradientStop Color="#FF797A7D" Offset="0.521"/>
            </LinearGradientBrush>
        </controls:UserControlMultiTouchEnabled.Resources>

        <StackPanel Orientation="Vertical">
            <GroupBox Header="{Localize GroupBoxLabelImportMaterials, {StaticResource AssemblyName}, {StaticResource LocStrings}, DefaultValue=Import Materials}">
                <ListView VerticalAlignment="Top"
                      Visibility="{Binding Path=ImportedMaterials, Converter={StaticResource converterObjectRefToVisibility}}"
                      MouseMove="MouseMoveHandler"
                      StylusDown="StylusDownHandler"
                      ScrollViewer.CanContentScroll="True"
                      MaxHeight="450"
                      ItemsSource="{Binding ImportedMaterials}" 
                      SelectedItem="{Binding CurrentImportedMaterialSelection}"
                Margin="4,2">
                    <ListView.View>
(removed code)
                    </ListView.View>
                </ListView>
            </GroupBox>
        </StackPanel>
    </controls:UserControlMultiTouchEnabled>

奇怪的是,我可以在程序的早期循环中执行导致操纵处理器实例化超过一百万次的代码,只显示内存不足异常-看不到E_NOINTERFACE。Harumph.

我遇到了同样的问题,所以我发布了对我有效的解决方案。我使用第三方DLL在WPF应用程序中创建用户控件。当我直接启动我的应用程序时,它工作得很好——但是当我从另一个应用程序(这是正常的用法)启动它时,它失败了,出现了与上面完全相同的问题。
为了解决这个问题,我将用户控件的变量声明从XAML移到了代码后面。这意味着,当您创建变量并实例化它时,将加载相同的DLL,因此没有冲突。

就是这样;我不想那么做。我已经在上面添加了MaterialImportExportControl.xaml文件的修剪内容。我要重申,这段代码适用于另一个几乎相同的应用程序,甚至在不同的情况下也适用于此应用程序。我缺少一些部署时的微妙之处…………如果您使用的是visual studio,是否可以转到
Debug>Exceptions
,检查抛出的“公共语言运行时异常”并重新运行?这可能会提供一些线索。如果调试器失败,这会有所帮助。当然,事实并非如此。好主意。我还通过Fusion Logger运行了它,这并不表明任何东西都失败了。记录的另一个线索。。。似乎失败的程序通过WCF“对话”的程序必须在Visual Studio宿主下运行,否则问题不会发生。目前,出现异常的原因似乎是试图获取操纵处理器的操作发生在主UI线程以外的其他线程上。。。。
System.Windows.Markup.XamlParseException occurred
  Message="Cannot create instance of 'JobDockControlH' defined in assembly 'cutterUIControls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation.  Error at object 'System.Windows.Controls.Grid' in markup file 'cutterUIControls;component/jobqueueviewh/xaml/jobstagingcontrolh.xaml' Line 94 Position 22."
  Source="PresentationFramework"
  LineNumber=94
  LinePosition=22
  NameContext="slidingDockBorder"
  StackTrace:
       at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)
  InnerException: System.Reflection.TargetInvocationException
       Message="Exception has been thrown by the target of an invocation."
       Source="mscorlib"
       StackTrace:
            at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
            at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
            at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
            at System.Activator.CreateInstance(Type type, Boolean nonPublic)
            at System.Windows.Markup.BamlRecordReader.CreateInstanceFromType(Type type, Int16 typeId, Boolean throwOnFail)
       InnerException: System.TypeInitializationException
            Message="The type initializer for 'Lightning.JobReviewer.JobReviewViewModel' threw an exception."
            Source="Lightning.UI.Controls"
            TypeName="Lightning.JobReviewer.JobReviewViewModel"
            StackTrace:
                 at Lightning.JobReviewer.JobReviewViewModel.get_Instance()
                 at JobQueueViewH.JobDockViewModelH..ctor() in C:\Development\RonAchin\Dev\Z12.0\Endeavor\cutterUIControls\JobQueueViewH\cs\JobDockViewModelH.cs:line 239
                 at JobQueueViewH.JobDockControlH..ctor() in C:\Development\RonAchin\Dev\Z12.0\Endeavor\cutterUIControls\JobQueueViewH\XAML\JobDockControlH.xaml.cs:line 142
            InnerException: System.InvalidCastException
                 Message="Unable to cast COM object of type 'Windows7.Multitouch.ManipulationInterop.ManipulationProcessor' to interface type 'Windows7.Multitouch.ManipulationInterop.IManipulationProcessor'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{A22AC519-8300-48A0-BEF4-F1BE8737DBA4}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."
                 Source="Windows7.Multitouch"
                 StackTrace:
                      at Windows7.Multitouch.ManipulationInterop.ManipulationProcessor.set_SupportedManipulations(MANIPULATION_PROCESSOR_MANIPULATIONS value)
                      at Windows7.Multitouch.Manipulation.ManipulationProcessor.set_SupportedManipulations(ProcessorManipulations value) in C:\D\Visual Studio 2008\Projects\Lightning\Dev\Zx\References\Windows7Multitouch\Mutitouch\Windows7.Multitouch\ManipulationProcessor.cs:line 461
                      at Windows7.Multitouch.Manipulation.ManipulationProcessor..ctor(ProcessorManipulations supportedManipulations) in C:\D\Visual Studio 2008\Projects\Lightning\Dev\Zx\References\Windows7Multitouch\Mutitouch\Windows7.Multitouch\ManipulationProcessor.cs:line 402
                      at Lightning.JobReviewer.JobReviewViewModel..ctor() in C:\Development\RonAchin\Dev\Z12.0\Endeavor\Controls\JobReviewer\cs\JobReviewViewModel.cs:line 93
                      at Lightning.JobReviewer.JobReviewViewModel..cctor() in C:\Development\RonAchin\Dev\Z12.0\Endeavor\Controls\JobReviewer\cs\JobReviewViewModel.cs:line 136
                 InnerException: