dotnet / dotnet-api-docs

.NET API reference documentation (.NET 5+, .NET Core, .NET Framework)
https://docs.microsoft.com/dotnet/api/
Other
727 stars 1.56k forks source link

FileSystemSecurity.xml: The example doesn't compile, contains non-existent method, no typos #9180

Open skycommand opened 1 year ago

skycommand commented 1 year ago

Hello

I'm reporting a faulty example code in the FileSystemSecurity Class page for .NET 7.0 (and potentially other versions). The associated source page is FileSystemSecurity.xml

The code doesn't compile (generating four CS0117 errors) because it calls two non-existent methods: File.GetAccessControl() and File.SetAccessControl().

Please advise.

ghost commented 1 year ago

Tagging subscribers to this area: @dotnet/area-system-security, @vcsjones See info in area-owners.md if you want to be subscribed.

Issue Details
Hello I'm reporting a faulty example code in the [FileSystemSecurity Class](https://learn.microsoft.com/en-us/dotnet/api/system.security.accesscontrol.filesystemsecurity?view=net-7.0&source=docs) page for .NET 7.0 (and potentially other versions). The associated source page is [FileSystemSecurity.xml](https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Security.AccessControl/FileSystemSecurity.xml) The code doesn't compile (generating four CS0117 errors) because it calls two non-existent methods: `File.GetAccessControl()` and `File.SetAccessControl()`. - In the C# version, the bad calls are on lines 44, 51, 61, and 68. - In the VB version, the bad calls are on lines 38, 47, 58, and 65. - In the C++ version, the bad calls are on lines 12, 19, 30, and 37. Please advise.
Author: skycommand
Assignees: -
Labels: `area-System.Security`, `untriaged`, `Pri3`
Milestone: -
jozkee commented 1 year ago

The example needs to be updated to use FileSystemAclExtensions. Instead of File.GetAccessControl(fileName), we need new FileInfo(fileName).GetAccessControl().

Although the existing example may still have value for .NET framework users. @gewarren is there a way to make tfm-specific examples?

gewarren commented 1 year ago

@gewarren is there a way to make tfm-specific examples?

@Jozkee Yes you can have have more than one example and just annotate them with the versions they apply to.