RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.73k stars 1.29k forks source link

NSwag accesses incorrect path for contracts #4544

Open CollinAlpert opened 11 months ago

CollinAlpert commented 11 months ago

When generating a C# client and selecting the "Generate contracts output" option, NSwag tries to access a folder which does not exist:

image

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.UnauthorizedAccessException: Access to the path 'C:\Program Files (x86)\Rico Suter\NSwagStudio\Contracts' is denied.

Runtime: Net70
   at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.File.OpenHandle(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
   at System.IO.File.WriteToFile(String path, FileMode mode, String contents, Encoding encoding)
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
   --- End of inner exception stack trace ---
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at NJsonSchema.Infrastructure.DynamicApis.FileWriteAllText(String filePath, String text)
   at NSwag.Commands.OutputCommandExtensions.TryWriteFileOutputAsync(IOutputCommand command, String path, IConsoleHost host, NewLineBehavior newLineBehavior, Func`1 generator) in /_/src/NSwag.Commands/Commands/OutputCommandExtensions.cs:line 49
   at NSwag.Commands.OutputCommandBase.TryWriteFileOutputAsync(String path, IConsoleHost host, Func`1 generator) in /_/src/NSwag.Commands/Commands/OutputCommandBase.cs:line 92
   at NSwag.Commands.CodeGeneration.SwaggerToCSharpClientCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in /_/src/NSwag.Commands/Commands/CodeGeneration/OpenApiToCSharpClientCommand.cs:line 251
   at NSwag.Commands.NSwagDocument.<>c__DisplayClass4_1.<<ExecuteAsync>b__0>d.MoveNext() in /_/src/NSwag.Commands/NSwagDocument.cs:line 95
--- End of stack trace from previous location ---
   at NSwag.Commands.NSwagDocument.ExecuteAsync() in /_/src/NSwag.Commands/NSwagDocument.cs:line 100
   at NSwag.Commands.Document.ExecuteDocumentCommand.ExecuteDocumentAsync(IConsoleHost host, String filePath) in /_/src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs:line 85
   at NSwag.Commands.Document.ExecuteDocumentCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in /_/src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs:line 32
   at NConsole.CommandLineProcessor.ProcessSingleAsync(String[] args, Object input)
   at NConsole.CommandLineProcessor.ProcessAsync(String[] args, Object input)
   at NSwag.Commands.NSwagCommandProcessor.ProcessAsync(String[] args) in /_/src/NSwag.Commands/NSwagCommandProcessor.cs:line 61
chrisrlewis commented 2 weeks ago

I get the same error - anybody advise? I've manually created the folder at the path shown above and removed access restrictions, yet still get the error.