Skip to content

SetFileInformationByHandle uses incorrect parameters on Win32 #95096

@smx-smx

Description

@smx-smx

Description

System.IO.File.SetLastWriteTime throws an exception on NFS, without setting the modification time.
NFS does however supports setting the last modification time (the touch command from Cygwin works, for example)

This breaks MSBuild, among other things, as seen here: dotnet/sdk#13808

Reproduction Steps

mount NFS

mount [remote] T:
T: is now successfully connected to [remote]

source code

Console.WriteLine("Hello, dotnet " + Environment.Version);

var t = DateTime.Now.Subtract(TimeSpan.FromDays(1));
System.IO.File.SetLastWriteTime(@"T:\thefile.txt", t);

output

Hello, dotnet 8.0.0
Unhandled exception. System.IO.IOException: The parameter is incorrect. : 'T:\thefile.txt'
   at System.IO.FileSystem.SetFileTime(SafeFileHandle fileHandle, String fullPath, Int64 creationTime, Int64 lastAccessTime, Int64 lastWriteTime, Int64 changeTime, UInt32 fileAttributes)
   at System.IO.FileSystem.SetFileTime(String fullPath, Boolean asDirectory, Int64 creationTime, Int64 lastAccessTime, Int64 lastWriteTime, Int64 changeTime, UInt32 fileAttributes)
   at System.IO.FileSystem.SetLastWriteTime(String fullPath, DateTimeOffset time, Boolean asDirectory)
   at System.IO.File.SetLastWriteTime(String path, DateTime lastWriteTime)
   at Program.<Main>$(String[] args) in G:\projects\nfs-issue\Program.cs:line 4

Expected behavior

Last modification time should be set correctly

Actual behavior

An unhandled exception is thrown

Unhandled exception. System.IO.IOException: The parameter is incorrect. : 'T:\thefile.txt'
   at System.IO.FileSystem.SetFileTime(SafeFileHandle fileHandle, String fullPath, Int64 creationTime, Int64 lastAccessTime, Int64 lastWriteTime, Int64 changeTime, UInt32 fileAttributes)
   at System.IO.FileSystem.SetFileTime(String fullPath, Boolean asDirectory, Int64 creationTime, Int64 lastAccessTime, Int64 lastWriteTime, Int64 changeTime, UInt32 fileAttributes)
   at System.IO.FileSystem.SetLastWriteTime(String fullPath, DateTimeOffset time, Boolean asDirectory)
   at System.IO.File.SetLastWriteTime(String path, DateTime lastWriteTime)
   at Program.<Main>$(String[] args) in G:\projects\nfs-issue\Program.cs:line 4

Regression?

It appears to be an old standing issue, present at least since 2019.

Known Workarounds

None

Configuration

.NET 8.0.100, on Windows 10 21H2 x64.

Other information

I found the following linked issues. It's been observed in mono too

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions