Skip to content

Emit a warning when referencing console applications exe's without a main #602

Description

@tldrlol

Create a solution with two Console Application projects:

ConsoleApplication1\Program.fs:

module SharedValue
let hello = "Hello" |> id

ConsoleApplication2\Program.fs (references ConsoleApplication1)

match SharedValue.hello with
| null -> printfn "SharedValue.hello is null!"
| _    -> printfn "all good"

Expected output: all good
Actual output: SharedValue.hello is null!

needless to say, getting a null value from an F# project is quite surprising.

Changing the type of ConsoleApplication1 to a Library fixes this.

Activity

  1. enricosada commented on Aug 25, 2015

    @enricosada
    Contributor

    i think is the same problem as fsharp/fsharp#326 , the console project doesn't initialize hello because you dont declare/execute the main function.

    see @latkin 's comment for detailed explaination and workaround

    @latkin @dsyme we need to add a warning? with c# you can reference the console app without problem, so is a bit unintuitive/annoying

  2. dsyme commented on Aug 25, 2015

    @dsyme
    Contributor

    Yrs, an explicit Main is required, and this is currently considered by design, for better or worse.

    Adding a warning on referencing such a component may well be feasible.

  3. enricosada commented on Aug 25, 2015

    @enricosada
    Contributor

    What's best?

    1. warning (error?) if a console app doesnt have a main
    2. warning if a referenced fsharp assembly (discriminate on .exe extension?) doesn't have a main
  4. dsyme commented on Aug 25, 2015

    @dsyme
    Contributor

    #2 - emit an attribute or other bit when no main on .exe, and detect that when the component is referenced

  5. dsyme commented on Aug 25, 2015

    @dsyme
    Contributor

    #2 - emit an attribute or other bit when no main on .exe, and detect that when the component is referenced

  6. changed the title [-]no initialization of modules in referenced console applications[/-] [+]emit a warning when referencing console applications exe's without a main[/+] on Jan 9, 2016
  7. added this to the Unknown milestone on Aug 25, 2018
  8. 1 remaining item

  9. added
    Impact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.
    and removed on Sep 16, 2021
  10. changed the title [-]emit a warning when referencing console applications exe's without a main[/-] [+]Emit a warning when referencing console applications exe's without a main[/+] on Nov 4, 2021
  11. added
    Area-Diagnosticsmistakes and possible improvements to diagnostics
    and removed on Mar 31, 2022
  12. github-actions commented on Sep 25, 2026

    @github-actions
    Contributor

    🤖 This is an automated response from Repo Assist.

    Confirmed this still reproduces at commit 7bcc3aea97ce976a1a6644d9bcceb518acfc5298 (2026-09-24), using the compiler produced by the current Release build's Proto stage:

    Microsoft (R) F# Interactive version 15.2.101.0 for F# 11.0
    Language Version: 11.0
    FSharp.Core: 11.0.0.0
    .NET: .NET 11.0.0-rc.1.26420.103
    OS: Linux 6.17.0-1022-azure (X64)
    

    I compiled the two-file repro from the issue as separate executables, with the second referencing the first. Both compiler invocations completed with no diagnostics. Running the consumer prints:

    SharedValue.hello is null!
    

    So the requested diagnostic is still absent: referencing an F# executable with no explicit entry point does not warn that its top-level bindings will remain uninitialized.

    Warning

    Firewall blocked 1 domain

    The following domain was blocked by the firewall during workflow execution:

    • southcentralus0.in.applicationinsights.azure.com

    To allow these domains, add them to the network.allowed list in your workflow frontmatter:

    network:
      allowed:
        - defaults
        - "southcentralus0.in.applicationinsights.azure.com"

    See Network Configuration for more information.

    Generated by 🌈 Repo Assist, see workflow run. Learn more.

    Add this agentic workflows to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/repo-assist.md@7c7feb61a52b662eb2089aa2945588b7a200d404
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Diagnosticsmistakes and possible improvements to diagnosticsBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.Theme-Simple-F#A cross-community initiative called "Simple F#", keeping people in the sweet spot of the language.

    Type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions