Search code examples
c#windows-installeraodl

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


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

enter image description here

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.


Solution

  • 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