zstewart
zstewart

Reputation: 2177

No line numbers despite PDB being generated

I have a C# project that isn't displaying line numbers in exceptions, despite the fact that PDB files are generated and present alongside the exe.

I am working on Linux using the dotnet tool to build and run. I am targeting net48 because the library I am building is intended for use in Unity so I can't really target more recent C# versions. I have tried setting DebugType to both full and embedded.

I can reproduce the issue with a minimal solution:

LineNumbers.sln

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LineNumbers", "LineNumbers\LineNumbers.csproj", "{EB46C6B5-C01C-4086-8FDC-1B5131F54683}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
        Release|Any CPU = Release|Any CPU
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {EB46C6B5-C01C-4086-8FDC-1B5131F54683}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {EB46C6B5-C01C-4086-8FDC-1B5131F54683}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {EB46C6B5-C01C-4086-8FDC-1B5131F54683}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {EB46C6B5-C01C-4086-8FDC-1B5131F54683}.Release|Any CPU.Build.0 = Release|Any CPU
    EndGlobalSection
EndGlobal

LineNumbers/LineNumbers.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net48</TargetFramework>
    <Nullable>enable</Nullable>
    <LangVersion>8.0</LangVersion>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
  </PropertyGroup>

</Project>

LineNumbers/Program.cs

using System;

namespace Example {
    public static class Program {
        public static void Main(string[] args) {
            throw new Exception("Line numbers?");
        }
    }
}

Running with dotnet run produces a stack trace with no line numbers or file names:

$ dotnet run --project LineNumbers

Unhandled Exception:
System.Exception: Line numbers?
  at Example.Program.Main (System.String[] args) [0x00001] in <01355b6ef5f04d7b84cb7aae45800d45>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.Exception: Line numbers?
  at Example.Program.Main (System.String[] args) [0x00001] in <01355b6ef5f04d7b84cb7aae45800d45>:

I also get the same result if I explicitly run the generated binary using mono:

$ mono LineNumbers/bin/Debug/net48/LineNumbers.exe

Unhandled Exception:
System.Exception: Line numbers?
  at Example.Program.Main (System.String[] args) [0x00001] in <01355b6ef5f04d7b84cb7aae45800d45>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.Exception: Line numbers?
  at Example.Program.Main (System.String[] args) [0x00001] in <01355b6ef5f04d7b84cb7aae45800d45>:0

Checking the output folder, the PDB is generated:

$ ls LineNumbers/bin/Debug/net48/            
LineNumbers.exe  LineNumbers.exe.config  LineNumbers.pdb

Additional system version information:

$ dotnet --version                
8.0.104
$ mono --version
Mono JIT compiler version 6.12.0.199 (tarball Wed May  1 05:08:53 UTC 2024)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
    TLS:           __thread
    SIGSEGV:       altstack
    Notifications: epoll
    Architecture:  amd64
    Disabled:      none
    Misc:          softdebug 
    Interpreter:   yes
    LLVM:          supported, not enabled.
    Suspend:       hybrid
    GC:            sgen (concurrent by default)
$ uname -r
6.8.11-300.fc40.x86_64
$ rpm -E %fedora
40

How can I get line numbers to show up in exceptions?

Upvotes: 0

Views: 40

Answers (0)

Related Questions