Hi there,
I'm on a mac with dotnet 2.1.4 installed. I publish my app with
dotnet publish --self-contained -r osx-x64 -c Release -o ./release ./MyApi
(I've also tried specifying the linux-x64 runtime). Then I run
nswag webapi2swagger /assembly:MyApi.dll /output:TestSwag.json /runtime:NetCore20
(I've also tried specifying the referencePaths to
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the path specified.
I can see that dll is in the folder from which I run nswag so I don't know what's going on or how to direct it to find the file. Thanks so much for the help in advance, really grateful to have found this project, just need to get past this last thing.
I think this is fixed in the next release
See https://github.com/RSuter/NSwag/issues/1162#issuecomment-362341106
Hi @RSuter ,
Thanks so much for the quick reply. I've been using the npm nswag package which is at 11.13.2.0, seems to be the same version from the NSwagStudio artifacts in the comment linked. So it would be the version after that? Thanks again.
You can download the ci version and install it even if it has the same version, otherwise it will be released as the next version
I downloaded the NSwag.zip artifact, extracted and used its NetCore20 dotnet-swag.dll to run like so:
dotnet ~/Downloads/NSwag/NetCore20/dotnet-nswag.dll webapi2swagger /assembly:MyApi.dll /output:TestSwag.json
but unfortunately got the same error as before.
Thanks again for the help @RSuter , really appreciate it.
Ok, it seems that the problem is, that some required DLLs are missing. Possible solutions here: https://github.com/RSuter/NSwag/wiki/Assembly-loading#net-core
Hi @RSuter ,
Sorry for the delay getting back. I tried with both the ReferencePaths arg on nswag and <PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest> set in the project when publishing and made sure that the Microsoft.AspNetCore.Mvc.Core dll did exist in the directory when I ran the nswag webapi2swagger ... but still got the same thing. I'm inclined to think it is a macos/linux (I tried on a dotnet linux container as well) issue because I ran the same process (publish then nswag) on windows and it runs correctly, generating the spec without issue. Is that possible? Thanks again.
Yes, this can be a problem with MacOS/Linux. The problem is that there are extremely many different ways to use NSwag (platforms, tools, .net versions, etc.) so it is very hard to test everything. Have you tried:
~/.nuget/packages as ReferencePaths (macos)I just updated my npm nswag package to 11.13.3 and tried again (also with /referencePaths:~/.nuget/packages) but unfortunately still got the same error (can't find Microsoft.AspNetCore.Mvc.Core, Version=2.0.0.0) on mac. Thanks again for the quick response and help, I know it's difficult to manage all of these platforms.
maybe you have to try with quotes :-) /referencePaths:"~/.nuget/packages"
But I think that reading a DLL version is not possible in Linux/MacOS and thus using ~/.nuget/packages is not a good idea as it would just load the first Microsoft.AspNetCore.Mvc.Core which is found...
If you set /referencePaths to the output directory where the correct DLL is available?
I originally ran it with an absolute since I didn't think it'd interpret the ~ correctly but also tried it with the quotes (had my fingers crossed that quotes would do it haha). I also had tried by setting the referencePaths to the release directory (instead of ~/.nuget/packages) where both my assembly dll and Microsoft.AspNetCore.Mvc.Core dll but still no luck (reran it again just now to be sure).
Can you post the complete NSwag cmd line output?
Of course, here's the full error output
NSwag NPM CLI
NSwag command line tool for .NET Core NetCore20, toolchain v11.13.3.0 (NJsonSchema v9.10.22.0 (Newtonsoft.Json v9.0.0.0))
Visit http://NSwag.org for more information.
NSwag bin directory: usr/local/lib/node_modules/nswag/bin/binaries/NetCore20
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Mvc.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the path specified.
File name: 'Microsoft.AspNetCore.Mvc.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
at System.Reflection.RuntimeAssembly.GetExportedTypes()
at NSwag.SwaggerGeneration.WebApi.WebApiToSwaggerGenerator.GetControllerClasses(Assembly assembly) in C:\projects\nswag\src\NSwag.SwaggerGeneration.WebApi\WebApiToSwaggerGenerator.cs:line 50
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.SelectEnumerableIterator`2.ToArray()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.OrderedEnumerable`1.ToArray()
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at NSwag.Commands.SwaggerGeneration.WebApiToSwaggerCommand.GetControllerNames(AssemblyLoader assemblyLoader) in C:\projects\nswag\src\NSwag.Commands\Commands\SwaggerGeneration\WebApiToSwaggerCommand.cs:line 261
at NSwag.Commands.SwaggerGeneration.WebApiToSwaggerCommand.<RunIsolatedAsync>d__88.MoveNext() in C:\projects\nswag\src\NSwag.Commands\Commands\SwaggerGeneration\WebApiToSwaggerCommand.cs:line 185
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NSwag.Commands.IsolatedCommandBase`1.IsolatedCommandAssemblyLoader`1.Run(String commandType, String commandData, String[] assemblyPaths, String[] referencePaths) in C:\projects\nswag\src\NSwag.Commands\Commands\IsolatedCommandBase.cs:line 59
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NSwag.Commands.IsolatedCommandBase`1.<RunIsolatedAsync>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NSwag.Commands.IsolatedSwaggerOutputCommandBase.<RunAsync>d__4.MoveNext() in C:\projects\nswag\src\NSwag.Commands\Commands\IsolatedSwaggerOutputCommandBase.cs:line 24
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NConsole.CommandLineProcessor.<ProcessSingleAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NConsole.CommandLineProcessor.<ProcessAsync>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NConsole.CommandLineProcessor.Process(String[] args, Object input)
at NSwag.Commands.NSwagCommandProcessor.Process(String[] args) in C:\projects\nswag\src\NSwag.Commands\NSwagCommandProcessor.cs:line 54
child_process.js:611
throw err;
^
Error: Command failed: dotnet "/usr/local/lib/node_modules/nswag/bin/binaries/NetCore20/dotnet-nswag.dll" webapi2swagger /assembly:MyApi.dll /DefaultPropertyNameHandling:CamelCase /output:MyClient/MyApiSwagSpec.json /runtime:NetCore20 /referencePaths:/Users/MYUSER/Projects/MyApi/MyApi/release/
at checkExecSyncError (child_process.js:568:13)
at Object.execSync (child_process.js:608:13)
at c.exec (/usr/local/lib/node_modules/nswag/bin/nswag.js:53:19)
at ChildProcess.exithandler (child_process.js:244:7)
at emitTwo (events.js:125:13)
at ChildProcess.emit (events.js:213:7)
at maybeClose (internal/child_process.js:887:16)
at Socket.stream.socket.on (internal/child_process.js:340:11)
at emitOne (events.js:115:13)
at Socket.emit (events.js:210:7)
v11.14.0:
We improved the assembly loader (mainly for .NET Core) so that it runs in a more isolated space and the loaded DLLs should better match the requested versions. Please test this with your projects to ensure that we didnt introduce regressions.
Important if you have DLL loading problems:
For more information regarding assembly loading: https://github.com/RSuter/NSwag/wiki/Assembly-loading
Main commit: https://github.com/RSuter/NSwag/commit/04576e4d1b714ac5bd9b5df11d72469a23f7c0ff#diff-14dafe6661bab407ae5c0d7095ccd1f4
Hey @RSuter ,
Thanks so much! 11.14.0 seems to have resolved this issue. The spec is now generated properly on mac. Thanks again for awesome work and the quick turn-around, really appreciate it.