Skip to content

Commit

Permalink
fix(PropertySerialization): fix null reference exception
Browse files Browse the repository at this point in the history
Methods don't necessarily have a body in IL so this fix ensures
these "empty methods" are not enumerated, preventing a null
reference exception from being thrown.
  • Loading branch information
Christopher - Marcel Böddecker committed Mar 3, 2019
1 parent 1404254 commit 97fdf72
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Sources/PropertySerializationAttribute.Fody/ModuleWeaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ private void ConfigureBackingField(FieldReference backingFieldReference, Propert
if (backingFieldDefinition != backingFieldReference)
{
IEnumerable<FieldReference> otherFieldReferences = propertyDefinition.DeclaringType.Methods
.SelectMany(definition => definition.Body?.Instructions)
.Where(definition => definition.HasBody)
.SelectMany(definition => definition.Body.Instructions)
.Select(instruction => instruction.Operand as FieldReference)
.Where(reference => reference?.FullName == previousFieldName);
foreach (FieldReference otherFieldReference in otherFieldReferences)
Expand Down

0 comments on commit 97fdf72

Please sign in to comment.