diff --git a/src/Umbraco.Core/Services/PackagingService.cs b/src/Umbraco.Core/Services/PackagingService.cs index 7784e5d76f..ccfe885adf 100644 --- a/src/Umbraco.Core/Services/PackagingService.cs +++ b/src/Umbraco.Core/Services/PackagingService.cs @@ -582,21 +582,22 @@ namespace Umbraco.Core.Services foreach (XElement tempElement in templateElements) { var dependencies = new List(); - if (tempElement.Element("Master") != null && - string.IsNullOrEmpty(tempElement.Element("Master").Value) == false && - templateElements.Any(x => x.Element("Alias").Value == tempElement.Element("Master").Value)) + var elementCopy = tempElement; + + if (elementCopy.Element("Master") != null && + string.IsNullOrEmpty(elementCopy.Element("Master").Value) == false && + templateElements.Any(x => x.Element("Alias").Value == elementCopy.Element("Master").Value)) { - dependencies.Add(tempElement.Element("Master").Value); + dependencies.Add(elementCopy.Element("Master").Value); } - else if (tempElement.Element("Master") != null && - string.IsNullOrEmpty(tempElement.Element("Master").Value) == false && - templateElements.Any(x => x.Element("Alias").Value == tempElement.Element("Master").Value) == + else if (elementCopy.Element("Master") != null && + string.IsNullOrEmpty(elementCopy.Element("Master").Value) == false && + templateElements.Any(x => x.Element("Alias").Value == elementCopy.Element("Master").Value) == false) { - LogHelper.Info(string.Format("Template '{0}' has an invalid Master '{1}', so the reference has been ignored.", tempElement.Element("Alias").Value, tempElement.Element("Master").Value)); + LogHelper.Info(string.Format("Template '{0}' has an invalid Master '{1}', so the reference has been ignored.", elementCopy.Element("Alias").Value, elementCopy.Element("Master").Value)); } - XElement elementCopy = tempElement; var field = new TopologicalSorter.DependencyField { Alias = elementCopy.Element("Alias").Value,