Description
Description
Setting the timestamp on a file with the read-only attribute on Windows now succeeds and no longer throws an exception.
dotnet/runtime#62602
dotnet/runtime#62638
Version
.NET 7 Preview 1 and .NET 6.0.2 or later.
Previous behavior
Attempting to set a timestamp on Windows on a file with the read-only attribute set would throw UnauthorizedAccessException.
New behavior
The operation now succeeds.
Type of breaking change
- Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load/execute or different run-time behavior.
- Source incompatible: Source code may encounter a breaking change in behavior when targeting the new runtime/component/SDK, such as compile errors or different run-time behavior.
Reason for change
Customers gave feedback that they expected this to succeed. This also makes it consistent with Linux. Finally, the behavior was unintentional, caused by a bug.
Recommended action
In the unlikely case that existing code was expecting this to fail, the code should instead check for the read-only attribute using File.GetAttributes before attempting to set the time stamp.
Feature area
Core .NET libraries
Affected APIs
File.SetCreationTime(String, DateTime)
File.SetCreationTimeUtc(String, DateTime)
File.SetLastAccessTime(String, DateTime)
File.SetLastAccessTimeUtc(String, DateTime)
File.SetLastWriteTime(String, DateTime)
File.SetLastWriteTimeUtc(String, DateTime)