cc: @sbomer @eerhardt
Say you have a very simple console app with the following code:
using System;
using System.Diagnostics;
class Program
{
static void Main(string[] args)
{
StackTrace thisTrace = new StackTrace(fNeedFileInfo: true);
if (thisTrace.GetFrame(thisTrace.FrameCount - 1).GetFileLineNumber() == 0)
{
throw new Exception("Unable to retrieve line info");
}
}
}
This will work just fine if you try to run it in a self contained app, but if you pass in /p:PublishTrimmed=true then it will start throwing an exception. The reason is that after the linker trims the assembly and the PDB, StackTrace constructor will fail to find PDBs for the console app, particularly it will cause Metadata reader to fail this check: https://github.com/dotnet/runtime/blob/master/src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEReader.cs#L828-L832
// Validate that the PDB matches the assembly version
if (new BlobContentId(candidate.GetMetadataReader().DebugMetadataHeader!.Id) != id)
{
return false;
}
as that if check will find that the PDB doesn't match the assembly version any longer and the method body will return false, meaning a metadata provider won't be succesfully returned.
cc: @sbomer @eerhardt
Say you have a very simple console app with the following code:
This will work just fine if you try to run it in a self contained app, but if you pass in
/p:PublishTrimmed=truethen it will start throwing an exception. The reason is that after the linker trims the assembly and the PDB, StackTrace constructor will fail to find PDBs for the console app, particularly it will cause Metadata reader to fail this check: https://github.com/dotnet/runtime/blob/master/src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEReader.cs#L828-L832as that if check will find that the PDB doesn't match the assembly version any longer and the method body will return false, meaning a metadata provider won't be succesfully returned.