我目前在使用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文件,就会发生此错误。文件包含的内容无关紧要。将其构建操作设置为Page
或ApplicationDefinition
的单个空XAML文件足以显示此错误。
进一步查看诊断日志似乎错误发生在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()
这种例外可能是什么原因?
已采取的故障排除步骤但无效:
答案 0 :(得分:2)
在克里斯W的评论链接this article的帮助下,我能够弄清楚。在这种情况下,错误表示项目中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
相关问题(模板上的无效事件处理程序等)引起。