diff --git a/ILRepack/ReferenceFixator.cs b/ILRepack/ReferenceFixator.cs index 6bd75d45..46b5133c 100755 --- a/ILRepack/ReferenceFixator.cs +++ b/ILRepack/ReferenceFixator.cs @@ -71,9 +71,12 @@ private FieldReference Fix(FieldReference field) field.DeclaringType = Fix(field.DeclaringType); if (field.DeclaringType.IsDefinition && !field.IsDefinition) { - FieldDefinition def = ((TypeDefinition)field.DeclaringType).Fields.FirstOrDefault(x => x.Name == field.Name); + var matches = ((TypeDefinition)field.DeclaringType).Fields.Where(f => f.Name == field.Name).ToList(); + FieldDefinition def = matches.Count > 1 ? + matches.FirstOrDefault(f => f.FieldType.FullName == field.FieldType.FullName) : + matches.FirstOrDefault(); if (def == null) - throw new NullReferenceException("Field \"" + field + "\" not found in type \"" + field.DeclaringType + "\"."); + throw new NullReferenceException("Field \"" + field + "\" with field type \"" + field.FieldType + "\" not found in type \"" + field.DeclaringType + "\"."); return def; } field.FieldType = Fix(field.FieldType); diff --git a/ILRepack/RepackImporter.cs b/ILRepack/RepackImporter.cs index 5da50366..04a14c8c 100644 --- a/ILRepack/RepackImporter.cs +++ b/ILRepack/RepackImporter.cs @@ -318,7 +318,7 @@ private bool ShouldDrop(TMember member) where TMember : ICustomAttribut /// private void CloneTo(FieldDefinition field, TypeDefinition nt) { - if (nt.Fields.Any(x => x.Name == field.Name)) + if (nt.Fields.Any(x => x.Name == field.Name && x.FieldType.FullName == field.FieldType.FullName)) { return; }