Skip to content
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

Creating symbolic links without developer mode or elevation fails silently #62975

Closed
Tracked by #57205 ...
jozkee opened this issue Dec 17, 2021 · 10 comments · Fixed by #69150
Closed
Tracked by #57205 ...

Creating symbolic links without developer mode or elevation fails silently #62975

jozkee opened this issue Dec 17, 2021 · 10 comments · Fixed by #69150
Milestone

Comments

@jozkee
Copy link
Member

jozkee commented Dec 17, 2021

Tested on Windows 10 21H1 19043 without Developer Mode with .NET 6 RTM; it does not throw.

Originally posted by @wegylexy in #57205 (comment)

cc @iSazonov @adamsitnik.

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Dec 17, 2021
@ghost
Copy link

ghost commented Dec 17, 2021

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

Issue Details

Tested on Windows 10 21H1 19043 without Developer Mode with .NET 6 RTM; it does not throw.

Originally posted by @wegylexy in #57205 (comment)

Author: Jozkee
Assignees: -
Labels:

area-System.IO, untriaged

Milestone: -

@jozkee
Copy link
Member Author

jozkee commented Dec 17, 2021

The Windows API CreateSymbolicLinkW is silently failing and we just return what the API reports.

Posible options to deal with this:

  • Contact Windows team and discuss if they can fix CreateSymbolicLinkW.

  • After calling FileSystemInfo link = File.CreateSymbolicLink("link", "target");
    Check link.Exists in order to verify that it was indeed created. This also works as a workaround for its current state.

  • Is very likely that CreateSymbolicLinkW uses DeviceIoControl, we can investigate if using that function for symlink creation is more reliable.
    As a side note: we already use on FileSystemInfo.LinkTarget.

@jozkee jozkee removed the untriaged New issue has not been triaged by the area owner label Dec 17, 2021
@jozkee jozkee added this to the 7.0.0 milestone Dec 17, 2021
@iSazonov
Copy link
Contributor

If Windows team can not fix old (supported) Windows versions it is best to use DeviceIoControl and backport to .Net 6 as bug fix.

@wegylexy
Copy link
Contributor

I have something on production that assumes it doesn't throw and checks for existence afterwards. A user reports it throws on Windows 7 when not run as admin.

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label May 10, 2022
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label May 10, 2022
@jozkee
Copy link
Member Author

jozkee commented May 19, 2022

@wegylexy @Raffaello I talked with the Windows team and they pointed out that the silent failure was due to an error on our side, so I fixed it in the main branch. Could you please help me validaiting the fix for your scenarios with a nightly build of .NET 7? That way, we can propose porting the fix to .NET 6.

Download the nightly build from https://github.com/dotnet/installer#table (column main (7.0.x Runtime)), download the version ad-hoc to your platform.
Run your scenario targeting net7.0, and please let me know if it is now fixed.

@wegylexy
Copy link
Contributor

@jozkee We switched to use directory junction points and copying files instead, as typical users won't have developer mode enabled.
Now I just look forwards to QUIC datagram and NativeAOT in .NET 7.
So, I am going to just trust that you have fixed it.

@Raffaello
Copy link

@jozkee ok, i will have a look, just need to find some times, hopefully i should hace some in the weekend.

@Raffaello
Copy link

Raffaello commented May 19, 2022

@jozkee with .NET7-preview5 an exception has been thrown, so it fixes that doesn't silently failing.
image

test ref: https://github.com/BlueRedSkyLTD/PowerDir/blob/main/PowerDir.Tests/EscapeCodesThemesTest.cs#L116-L158
([TestMethod]) is commented as it won't work as a test as requires dev/admin privileges to create a symlink

@jozkee
Copy link
Member Author

jozkee commented May 19, 2022

Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Jun 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants