Skip to content

FileVersionInfo.GetVersionInfo does not return the same values on Windows and Linux #123174

@johanseb-te

Description

@johanseb-te

Description

There is an undocumented behavior difference in FileVersionInfo.GetVersionInfo, where the Windows version calls GetFileVersionInfoEx (which looks at the VsVersionTable) and the *nix version just parses the managed metadata. This means you get different results depending on OS if the binary is unmanaged, or the managed and unmanaged metadata differs.

There's an issue filed with the API docs to document this, and this issue was reported earlier in #40895 (which was closed after VsVersionTable and managed metadata was made to match, instead of fixing the parsing.)

Reproduction Steps

FileVersionInfo.GetVersionInfo("unmanaged.exe"); // Where 'unmanaged.exe' is any unmanaged PE executable (including DLL)

Expected behavior

Same values are returned on both Linux and Windows for both managed and unmanaged binaries.

Actual behavior

On Linux, unmanaged binaries won't have values set, and managed binaries will have values set to the managed metadata. On Windows, values will always be set to the VsVersionTable.

Regression?

No.

Known Workarounds

Use a third-party full PE parser like PeNet to manually get the values from the VsVersionTable.

Configuration

.NET 8, both Windows and Linux, x64. Not specific to the configuration, other than it being a platform difference.

Other information

Implementation lives in /src/libraries/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.Unix.cs and FileVersionInfo.Windows.cs.

In general, it's very unclear what FileVersionInfo is supposed to support, because all the documentation is as-is from the .NET Framework version. Should it support Windows binaries outside Windows? Should it be limited to the OS it's built for, in which case, should it support something like UAPI.8 Package Metadata?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions