diff --git a/src/XamlCompiler/BuildTasks/SourceFileManager.cs b/src/XamlCompiler/BuildTasks/SourceFileManager.cs index 7e7d554846..1bb1f80161 100644 --- a/src/XamlCompiler/BuildTasks/SourceFileManager.cs +++ b/src/XamlCompiler/BuildTasks/SourceFileManager.cs @@ -125,9 +125,10 @@ public void PropagateOutOfDateStatus(DirectUI.DirectUISchemaContext context) // look to see if a new class was specified; if so, we guessed wrong before, undo that. // Note that both the old and new classes are out of date. string newClassFullName = null; - using (var fileReader = TaskFileService.GetFileContents(tif.SourceXamlFullPath)) + if (!TryReadClassFullName(tif, context, out newClassFullName)) { - newClassFullName = XamlNodeStreamHelper.ReadXClassFromXamlFileStream(fileReader, context); + // Can't tell whether the class was renamed; leave the cached name, the file is already out of date. + continue; } if (newClassFullName != tif.ClassFullName) @@ -169,6 +170,24 @@ public void PropagateOutOfDateStatus(DirectUI.DirectUISchemaContext context) } } + // Returns false when the x:Class can't be determined (malformed markup, unreadable file, schema failure). + private bool TryReadClassFullName(TaskItemFilename tif, DirectUI.DirectUISchemaContext context, out string classFullName) + { + try + { + using (var fileReader = TaskFileService.GetFileContents(tif.SourceXamlFullPath)) + { + classFullName = XamlNodeStreamHelper.ReadXClassFromXamlFileStream(fileReader, context); + } + return true; + } + catch (Exception) + { + classFullName = null; + return false; + } + } + public TaskItemFilename FindTaskItemByFullPath(string fullPath) { foreach (TaskItemFilename tif in ProjectXamlTaskItems)