Skip to content

Commit

Permalink
fix icsharpcode#371 - BAML decompiler throws NullReferenceExceptions:…
Browse files Browse the repository at this point in the history
… if this cause occurs it should throw a better exception than just NRE
  • Loading branch information
siegfriedpammer committed May 11, 2013
1 parent 7423863 commit 0482ef9
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ ReaderContext Current {
int currentKey;
List<KeyMapping> keys = new List<KeyMapping>();

KeyMapping LastKey {
get { return keys.LastOrDefault(); }
}

void LayerPop()
{
layer.Pop();
Expand Down Expand Up @@ -1383,7 +1379,10 @@ void ReadStaticResourceStart()
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());
Expand Down Expand Up @@ -1454,8 +1453,11 @@ void ReadOptimizedStaticResource()
} 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)
Expand Down

0 comments on commit 0482ef9

Please sign in to comment.