Access to path denied while reading a dll from Program Files which is actually got from a nuget package

安稳与你 提交于 2020-01-25 08:39:05

问题


Access to path denied error is encountered in Program files (x86), while working with a DLL that is got from nuget package: AODL for reading ODF files - https://www.nuget.org/packages/AODL/ after I created a MSI file using SETUP Project

In the code, I don't suspect the file creation part for I create this file in the user chosen file conversion path but NOT IN PROGRAM FILES folder path:

File.WriteAllText(targetFileName, sb.ToString(), Encoding.UTF8);

That's why I simply suspect the DLL, please let me know how I could find the error and fix this.


回答1:


A bunch of directories - both Programm Files, the root directory of the System Drive, Windows - are heavily protected by NTFS rights. Writing them is usually a plain "no-go". Unless you run around with full administrative rights - wich only Instalers and very rare Adminsitrative tools should even consider - you will not be able to write there.

However you indicated this happens on a read. Reads being blocked like that is very unusual. You need to check what rights are set on those folders and why. Maybe the installer accidentally copied the rights from your computer, wich only makes sense with your users and groups? Maybe Windows or a third party broke those rights? Not a lot of options I can think of that could apply here.




回答2:


For this application, even for reading the DLLs from the Program Files folder I needed Admin rights so I forced the application to have such rights for execution.

The below line for the newly created application manifest file is changed and that solved the issue.

<requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />

The fix is explained well in How do I force my .NET application to run as administrator?

The reasons are stated well in https://stackoverflow.com/a/50588465/129130



来源:https://stackoverflow.com/questions/59416186/access-to-path-denied-while-reading-a-dll-from-program-files-which-is-actually-g

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!