From 0482ef91ed5da38dc72b4cf1e6b32ab6063afd4d Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 11 May 2013 16:32:10 +0200 Subject: [PATCH] fix #371 - BAML decompiler throws NullReferenceExceptions: if this cause occurs it should throw a better exception than just NRE --- .../XmlBamlReader.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs index 6a16e0482..12c55ae18 100644 --- a/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs +++ b/ILSpy.BamlDecompiler/Ricciolo.StylesExplorer.MarkupReflection/XmlBamlReader.cs @@ -75,10 +75,6 @@ namespace Ricciolo.StylesExplorer.MarkupReflection int currentKey; List keys = new List(); - KeyMapping LastKey { - get { return keys.LastOrDefault(); } - } - void LayerPop() { layer.Pop(); @@ -1383,7 +1379,10 @@ namespace Ricciolo.StylesExplorer.MarkupReflection short identifier = reader.ReadInt16(); byte flags = reader.ReadByte(); TypeDeclaration declaration = GetTypeDeclaration(identifier); - LastKey.StaticResources.Add(declaration); + var lastKey = keys.LastOrDefault(); + if (lastKey == null) + throw new InvalidOperationException("No key mapping found for StaticResourceStart!"); + lastKey.StaticResources.Add(declaration); XmlBamlElement element; if (elements.Any()) element = new XmlBamlElement(elements.Peek()); @@ -1454,8 +1453,11 @@ namespace Ricciolo.StylesExplorer.MarkupReflection } else { resource = this.stringTable[typeIdentifier]; } - - LastKey.StaticResources.Add(resource); + + var lastKey = keys.LastOrDefault(); + if (lastKey == null) + throw new InvalidOperationException("No key mapping found for OptimizedStaticResource!"); + lastKey.StaticResources.Add(resource); } string GetTemplateBindingExtension(PropertyDeclaration propertyDeclaration)