Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Refine GeneratePdbForAssemblies implementation.
  • Loading branch information
sonyps5201314 committed Nov 21, 2025
commit 5625db2a96d8f05ba6c916dec26c5cfbe69781dc
36 changes: 25 additions & 11 deletions ILSpy/Commands/GeneratePdbContextMenuEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,30 @@ internal static void GeneratePdbForAssemblies(IEnumerable<LoadedAssembly> assemb
return;

// Ensure at least one assembly supports PDB generation
if (!assemblyArray.Any(a => PortablePdbWriter.HasCodeViewDebugDirectoryEntry(a.GetMetadataFileOrNull() as PEFile)))
var supported = new Dictionary<LoadedAssembly, PEFile>();
var unsupported = new List<LoadedAssembly>();
foreach (var a in assemblyArray)
{
MessageBox.Show(Resources.CannotCreatePDBFile);
try
{
var file = a.GetMetadataFileOrNull() as PEFile;
if (PortablePdbWriter.HasCodeViewDebugDirectoryEntry(file))
supported.Add(a, file);
else
unsupported.Add(a);
}
catch
{
unsupported.Add(a);
}
}
if (supported.Count == 0)
{
// none can be generated
string msg = string.Format(Resources.CannotCreatePDBFile, ":" + Environment.NewLine +
string.Join(Environment.NewLine, unsupported.Select(u => Path.GetFileName(u.FileName)))
+ Environment.NewLine);
Comment on lines +148 to +150

Copilot AI Nov 24, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message formatting is incorrect. The first parameter to string.Format should be just the assembly filename, not a formatted string with additional content. This will result in a malformed error message like "Cannot create PDB file for :
Assembly1.dll
Assembly2.dll
because the PE debug directory type 'CodeView' is missing."

Consider changing this to properly format the list of unsupported assemblies, for example:

string msg = Resources.CannotCreatePDBFile + Environment.NewLine +
    string.Join(Environment.NewLine, unsupported.Select(u => "  - " + Path.GetFileName(u.FileName)));
MessageBox.Show(msg);
Suggested change
string msg = string.Format(Resources.CannotCreatePDBFile, ":" + Environment.NewLine +
string.Join(Environment.NewLine, unsupported.Select(u => Path.GetFileName(u.FileName)))
+ Environment.NewLine);
string msg = Resources.CannotCreatePDBFile + Environment.NewLine +
string.Join(Environment.NewLine, unsupported.Select(u => " - " + Path.GetFileName(u.FileName)));

Copilot uses AI. Check for mistakes.
MessageBox.Show(msg);
return;
}

Expand All @@ -154,15 +175,8 @@ internal static void GeneratePdbForAssemblies(IEnumerable<LoadedAssembly> assemb
int processed = 0;
foreach (var assembly in assemblyArray)
{
if (ct.IsCancellationRequested)
{
output.WriteLine();
output.WriteLine(Resources.GenerationWasCancelled);
throw new OperationCanceledException(ct);
}

var file = assembly.GetMetadataFileOrNull() as PEFile;
if (file == null || !PortablePdbWriter.HasCodeViewDebugDirectoryEntry(file))
// only process supported assemblies
if (!supported.TryGetValue(assembly, out var file))
{
output.WriteLine(string.Format(Resources.CannotCreatePDBFile, Path.GetFileName(assembly.FileName)));
processed++;
Expand Down
2 changes: 1 addition & 1 deletion ILSpy/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ Are you sure you want to continue?</value>
<value>Entity could not be resolved. Cannot analyze entities from missing assembly references. Add the missing reference and try again.</value>
</data>
<data name="CannotCreatePDBFile" xml:space="preserve">
<value>Cannot create PDB file for {0}, because it does not contain a PE Debug Directory Entry of type 'CodeView'.</value>
<value>Cannot create PDB file for {0} because the PE debug directory type 'CodeView' is missing.</value>
</data>
<data name="CheckAgain" xml:space="preserve">
<value>Check again</value>
Expand Down
2 changes: 1 addition & 1 deletion ILSpy/Properties/Resources.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
<value>无法解析实体。可能是由于缺少程序集引用。请添加缺少的程序集并重试。</value>
</data>
<data name="CannotCreatePDBFile" xml:space="preserve">
<value>无法创建为{0}创建PDB文件,因为它不包含PE调试目录类型 'CodeView'.</value>
<value>不能为 {0} 创建PDB文件,因为缺少PE调试目录类型 'CodeView'</value>
</data>
<data name="CheckAgain" xml:space="preserve">
<value>再次检查</value>
Expand Down
Loading