4

我目前在使用 Visual Studio 2015 构建通用 Windows 应用程序时遇到问题。每当我尝试编译我的项目时,都会收到以下错误:

Child node "2" exited prematurely. Shutting down. Diagnostic information may be found in files in the temporary files directory named MSBuild_*.failure.txt.

只要应用程序中存在 XAML 文件,就会发生此错误。文件包含什么并不重要。单个空 XAML 文件的构建操作设置为PageorApplicationDefinition足以使此错误出现。

进一步查看诊断日志,似乎错误发生在CompileXaml任务中,但有以下异常:

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at Microsoft.Windows.UI.Xaml.Build.Tasks.NativeMethods.WriteWithCheckSum(IStream[] xamlStreams, Int32 numFiles, String[] pbChecksum, Int32 checksumSize, IXbfMetadataProvider provider, TargetOSVersion targetVersion, UInt32 xbfGenerationFlags, IStream[] xbfStreams, Int32& errorCode, Int32& errorFileIndex, Int32& errorLine, Int32& errorColumn)
   at Microsoft.Xaml.XBF.XbfGenerator.GenerateXbfFromStreams(IStream[] inputStreams, IStream[] outputStreams, UInt32 xbfGenerationFlags, String[] checksums, TargetOSVersion targetOS, Int32& errorCode, Int32& errorFile, Int32& errorLine, Int32& errorPosition)
   at Microsoft.Xaml.XBF.XbfGenerator.GenerateAll(String targetPlatformVersion, UInt32 xbfGenerationFlags)
   at Microsoft.Xaml.XBF.XbfGenerator.GenerateXbfFiles(String targetPlatformVersion, UInt32 xbfGenerationFlags, Boolean v80Compat)
   at Microsoft.Windows.UI.Xaml.Build.Tasks.CompileXamlInternal.GenerateXbfFiles(List`1 xamlList)
   at Microsoft.Windows.UI.Xaml.Build.Tasks.CompileXamlInternal.DoExecute()
   at Microsoft.Windows.UI.Xaml.Build.Tasks.CompileXaml.Execute()

此异常的原因可能是什么?

已采取但无济于事的故障排除步骤:

  • 重启电脑
  • 重新安装 Visual Studio 和 .NET 框架
  • 从命令行构建
  • 以管理员身份启动 VS(或命令行)
4

1 回答 1

2

在 Chris W. 的评论中链接的这篇文章的帮助下,我能够弄清楚。在这种情况下,错误表明项目中的一个问题ResourceDictionary

事实证明ResourceDictionary,我的项目中的一个包含重复的命名空间声明。

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MyApp.UAP.Base">

    <Style TargetType="local:TTBasePage"  xmlns:local="using:MyApp.UAP.Base"> <!-- This line caused  the error -->
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:TTBasePage">
                    <Border
                        Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}">
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

删除这个重复的命名空间声明解决了构建错误。

根据文章,它也可能是由其他ResourceDictionary相关问题(模板上的无效事件处理程序等)引起的。

于 2015-12-08T08:50:45.193 回答