-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Path.GetFileNameWithoutExtension() does not throw ArgumentException ("Illegal characters in path") on Windows #72307
Comments
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsDescriptionI'm migrating a project from .NET Framework 4.7.2 to .NET 6.0. One of my tests is failing, and I have isolated the issue to Path.GetFileNameWithoutExtension seemingly handling the path like it is a Unix path. Consequently, it returns the entire path except the extension, and also incidentally does not throw if I had invalid (for Windows) characters in the path. Reproduction Stepsstring fileName = @"C:\mydir\myfile.ext"; result = Path.GetFileNameWithoutExtension(fileName); Expected behavior// EXPECTED: GetFileNameWithoutExtension('C:\mydir\myfile.ext') returns 'myfile' Actual behavior// ACTUAL: GetFileNameWithoutExtension('C:\mydir\myfile.ext') returns 'C:\mydir\myfile' on .NET 6.0 on Windows Regression?Maybe? Known WorkaroundsNo response Configuration.NET 6.0.7 Other informationNo response
|
Can't reproduce on (x86 64 bit) macOS, linux and w10/11 with latest .net6 and .net 7 prefiew. All return the expected result. |
I am not able to reproduce it either. @arvindshmicrosoft Could you please double check the repro steps and the result that you are seeing? |
This issue has been marked |
I can't repro it either, and from looking at the code, it's not clear to me how this could happen. |
Thank you all for looking. Something must be very specific to my case. I will investigate further and get back. |
@Fabi @jkotas @stephentoub - in the process of distilling the repro down, I had deviated from the core issue, which seems to be that the erstwhile |
That was intentional breaking change in .NET Core 2.1. More details in https://docs.microsoft.com/en-us/dotnet/core/compatibility/2.1#path-apis-dont-throw-an-exception-for-invalid-characters |
That was changed in .NET Core 2.1: |
@jkotas and @stephentoub thank you for pointing this out. I really appreciate the help. |
Description
I'm migrating a project from .NET Framework 4.7.2 to .NET 6.0. One of my tests is failing, and I have isolated the issue to Path.GetFileNameWithoutExtension seemingly handling the path like it is a Unix path. Consequently, it returns the entire path except the extension, and does not throw if I had invalid (for Windows) characters in the path.
Reproduction Steps
The csproj is below:
Expected behavior
ArgumentException should be thrown as the
<
and>
characters are invalid for Windows. In .NET Framework 4.7.2 for example, the above code results in the following exception:Actual behavior
Regression?
Maybe?
Known Workarounds
No response
Configuration
.NET 6.0.7
OS: Windows 11 - 10.0.22000 Build 22000
Architecture: x64
Other information
No response
The text was updated successfully, but these errors were encountered: