Skip to content

Changing PDB document URLs causes an exception #566

@bartuszekj

Description

@bartuszekj

Calling module.Write() after updating PDB document URLs causes a System.ArgumentException.

Code changing the URL is a simple path replacement method:

foreach (var doc in module.PdbState.Documents)
{
    var relPath = Path.GetRelativePath(sourcePath, doc.Url);
    doc.Url = Path.Combine(dstPath, relPath);
}

Exception and stack trace:

System.ArgumentException: An item with the same key has already been added. Key: 30000001
   at System.ThrowHelper.ThrowAddingDuplicateWithKeyArgumentException[T](T key)
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at dnlib.DotNet.Pdb.PdbState.Add_NoLock(SymbolDocument symDoc)
   at dnlib.DotNet.Pdb.PdbState.AddSequencePoints(CilBody body, SymbolMethod method)
   at dnlib.DotNet.Pdb.PdbState.InitializeMethodBody(ModuleDefMD module, MethodDef ownerMethod, CilBody body)
   at dnlib.DotNet.ModuleDefMD.InitializeBodyFromPdb(MethodDefMD method, CilBody body)
   at dnlib.DotNet.ModuleDefMD.ReadMethodBody(MethodDefMD method, RVA rva, MethodImplAttributes implAttrs, GenericParamContext gpContext)
   at dnlib.DotNet.MethodDefMD.GetMethodBody_NoLock()
   at dnlib.DotNet.MethodDef.InitializeMethodBody()
   at dnlib.DotNet.MethodDef.get_Body()
   at dnlib.DotNet.Writer.Metadata.WriteMethodBodies()
   at dnlib.DotNet.Writer.Metadata.Create()
   at dnlib.DotNet.Writer.Metadata.CreateTables()
   at dnlib.DotNet.Writer.ModuleWriter.WriteImpl()
   at dnlib.DotNet.Writer.ModuleWriterBase.Write(Stream dest)
   at dnlib.DotNet.Writer.ModuleWriterBase.Write(String fileName)
   at dnlib.DotNet.ModuleDef.Write(String filename, ModuleWriterOptions options)

The same exception is thrown when documents are removed via module.PdbState.RemoveAllDocuments() and then readded with new URLs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions