Given this snippet running on Windows:
string filePath = "myfile";
string linkTarget = "myfile.link";
FileInfo finfo = new(filePath);
FileInfo fi = new(linkTarget);
finfo.Create().Close();
Assert.IsTrue(finfo.Exists);
fi.CreateAsSymbolicLink(filePath);
Assert.IsTrue(fi.Exists); // here thrown, assert is false. And LinkTarger == null.
the symbolic link is not being created and doesn't exists.
It looks like a .NET6.0 bug to me.
what's wrong with it?
What am I missing?
How can i create a symbolic link using FileInfo
or related?
EDIT
I forgot that must be an admin to create a symbolic link in windows,
besides shouldn't throw instead a "NotAuthorized
" or something?
At this point if i want to create a symbolic link not as admin won't be possible then?
Based on this other answer. The reason why the file doesn't exists is because the program doesn't run with admin privileges
It looks like there is a policy to set up to allow non admin to create symlinks.