Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions ILRepack/RepackImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public TypeDefinition Import(TypeDefinition type, Collection<TypeDefinition> col
return null;
}

TypeDefinition nt = _repackContext.TargetAssemblyMainModule.GetType(type.FullName);
TypeDefinition nt = _repackContext.TargetAssemblyMainModule.Types.FirstOrDefault(x => x.Name == type.Name && x.Namespace == type.Namespace);
bool justCreatedType = false;
if (nt == null)
{
Expand All @@ -165,20 +165,23 @@ public TypeDefinition Import(TypeDefinition type, Collection<TypeDefinition> col
else if (!type.IsPublic || internalize)
{
var originalModule = _repackContext.MappingHandler.GetOriginalModule(nt);

_logger.Verbose($"- Renaming previously imported type {nt.FullName} from {originalModule.Name}");

// rename the type previously imported.
// renaming the new one before import made Cecil throw an exception.
string other = GenerateName(nt, originalModule?.Mvid.ToString());

//Check whether renamed type already exists
TypeDefinition otherNt = _repackContext.TargetAssemblyMainModule.GetType(other);
TypeDefinition otherNt = _repackContext.TargetAssemblyMainModule.Types.FirstOrDefault(x => x.Name == other && x.Namespace == nt.Namespace);
if (otherNt != null)
{
var otherOriginalModule = _repackContext.MappingHandler.GetOriginalModule(otherNt);
_logger.Verbose($"- Collision found with type {otherNt.FullName} from {otherOriginalModule.Name}. Renaming now to a random name");
//Create a random name
other = GenerateName(nt);
}

_logger.Verbose("Renaming " + nt.FullName + " into " + other);
_logger.Verbose($"- Renaming {nt.FullName} from {originalModule.Name} into {nt.Namespace}.{other}");
nt.Name = other;
nt = CreateType(type, col, internalize, null);
justCreatedType = true;
Expand Down