Skip to content

Variables do not show in debugger in top-level program #7456

@albahari

Description

@albahari

Repro steps

Create a new F# project in VS2019 that targets .NET Framework 4.6 or .NET Core, and type in the following program:

open System

let x = 2
let y = 3
let z = x + y

Console.WriteLine (z)

Set a breakpoint on the last line, press F5, and go to the "Locals Window".

Expected behavior

You should see three variables: x, y, and z. And in the Watch window, you should be able to type 'y' or 'z' to see the value of y or z.

Actual behavior

Only variable x appears. And if you type 'y' into the Watch window, it says "The name 'y' does not exist in the current context.'

Known workarounds.

If you do same thing in VS2017, x, y, and z are all visible.

Related information

I believe the problem is caused by a bug in the way the PDB file is generated in the newer version of VS/F#. You can verify this by running the following program without attaching the debugger (Ctrl+F5):

let x = 2
let y = 3
let z = x + y
System.Diagnostics.Debugger.Launch()

First, build the program in VS2017, and run with Ctrl+F5. When the just-in-time debugging prompt appears, choose VS2019 as your debugger - the debugger will work perfectly and you'll be able to see variables x, y and z.

Now do the reverse. Build the program in VS2019, and run with Ctrl+F5. When the just-in-time debugging prompt appears, choose VS2017 as your debugger - now you'll only be able to see variable x in the locals window.

Microsoft Windows [Version 10.0.18362.295]
VS2019 Microsoft Visual F# Tools 10.4 for F# 4.6
VS2017: Microsoft Visual F# Tools 10.2 for F# 4.5
Same behavior with .NET Framework 4.5 -> 4.8, and .NET Core 2.2 and 3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Debugstepping, debug points, stacks and moreBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.Ready

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions