ClangSharp icon indicating copy to clipboard operation
ClangSharp copied to clipboard

Getting UnauthorizedAccessException on output directory

Open JordyDew opened this issue 4 years ago • 1 comments

While executing the following command, I get an UnauthorizedAccessException for the output directory (-o flag): D:\Users\jordy\Downloads\liblouisutdml-2.10.0-win32\include\liblouis> ClangSharpPInvokeGenerator -f .\liblouis.h -n DewSystems.LibLouis -o .\test

The stack trace is the flowing:

                            
Unhandled exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.                            
                            
 ---> System.UnauthorizedAccessException: Access to the path 'D:\Users\jordy\Downloads\liblouisutdml-2.10.0-win32\include\liblouis\test' is denied.    
                            
   at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)                                                                               
                            
   at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)                                                   
                            
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)                
                            
   at System.IO.FileStream..ctor(String path, FileMode mode)                                                                                           
                            
   at ClangSharp.PInvokeGenerator.<>c.<.ctor>b__22_0(String path) in /_/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs:line 57                
                            
   at ClangSharp.PInvokeGenerator.Close() in /_/sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs:line 111                                       
                            
   at ClangSharp.Program.Run(InvocationContext context) in /_/sources/ClangSharpPInvokeGenerator/Program.cs:line 517                                   
                            
   --- End of inner exception stack trace ---                                                                                                          
                            
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)```

I tried executing this command in a normal command prompt and a shell with elevated rights (administrator rights). Twice the same result.

JordyDew avatar Mar 30 '21 09:03 JordyDew

Could you please try specifying an output file and not simply a directory?

The generator looks to be in single file mode, in which case I believe -o is required to be a file path. It works as a directory for -c multi-file (where you get a type per file).

I will look at improving the handling or error message here to improve the experience.

tannergooding avatar Mar 30 '21 14:03 tannergooding

The handling here is done by System.CommandLine now.

tannergooding avatar Jun 21 '23 18:06 tannergooding