NSwag: ASP.NET Core 2.1 Preview: FileNotFoundException for System.Diagnostics.Tools
Using NSwag.MSBuild v11.15.4
Updated my ASP.NET Core application to TargetFramework netcoreapp2.1, build now fails with the below error.
1>NSwag command line tool for .NET Core NetCore20, toolchain v11.15.4.0 (NJsonSchema v9.10.29.0 (Newtonsoft.Json v9.0.0.0))
1>Visit http://NSwag.org for more information.
1>NSwag bin directory: C:\Users\c-tjarzombek\.nuget\packages\nswag.msbuild\11.15.4\build\NetCore20
1>System.IO.FileNotFoundException: Could not load file or assembly 'System.Diagnostics.Tools, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
1>File name: 'System.Diagnostics.Tools, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.IO.FileNotFoundException: Could not load the specified file.
1>File name: 'System.Diagnostics.Tools'
1> at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingEvent(AssemblyName assemblyName)
1> at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingResolvingEvent(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
1> at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
1> at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
1> at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
1> at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
1> at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
1> at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
1> at System.Attribute.GetCustomAttributes(MemberInfo element, Boolean inherit)
1> at NSwag.SwaggerGeneration.WebApi.WebApiToSwaggerGenerator.<>c.<GetControllerClasses>b__3_4(Type t) in C:\projects\nswag\src\NSwag.SwaggerGeneration.WebApi\WebApiToSwaggerGenerator.cs:line 58
1> at System.Linq.Utilities.<>c__DisplayClass1_0`1.<CombinePredicates>b__0(TSource x)
1> at System.Linq.Enumerable.WhereArrayIterator`1.MoveNext()
1> at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
1> at System.Linq.Enumerable.SelectEnumerableIterator`2.ToArray()
1> at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
1> at System.Linq.OrderedEnumerable`1.ToArray()
1> at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
1> at NSwag.Commands.SwaggerGeneration.WebApiToSwaggerCommand.GetControllerNames(AssemblyLoader assemblyLoader) in C:\projects\nswag\src\NSwag.Commands\Commands\SwaggerGeneration\WebApiToSwaggerCommand.cs:line 268
1> at NSwag.Commands.SwaggerGeneration.WebApiToSwaggerCommand.<RunIsolatedAsync>d__91.MoveNext() in C:\projects\nswag\src\NSwag.Commands\Commands\SwaggerGeneration\WebApiToSwaggerCommand.cs:line 192
1>--- End of stack trace from previous location where exception was thrown ---
1> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
1> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
1> 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 60
1> at NSwag.Commands.IsolatedCommandBase`1.<>c__DisplayClass13_0.<RunIsolatedAsync>b__0() in C:\projects\nswag\src\NSwag.Commands\Commands\IsolatedCommandBase.cs:line 50
1> at System.Threading.Tasks.Task`1.InnerInvoke()
1> at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
1> at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
1>--- End of stack trace from previous location where exception was thrown ---
1> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
1> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
1> at NSwag.Commands.IsolatedCommandBase`1.<RunIsolatedAsync>d__13.MoveNext()
1>--- End of stack trace from previous location where exception was thrown ---
1> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
1> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
1> at NSwag.Commands.IsolatedSwaggerOutputCommandBase.<RunAsync>d__4.MoveNext() in C:\projects\nswag\src\NSwag.Commands\Commands\IsolatedSwaggerOutputCommandBase.cs:line 24
1>--- End of stack trace from previous location where exception was thrown ---
1> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
1> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
1> at NConsole.CommandLineProcessor.<ProcessSingleAsync>d__12.MoveNext()
1>--- End of stack trace from previous location where exception was thrown ---
1> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
1> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
1> at NConsole.CommandLineProcessor.<ProcessAsync>d__11.MoveNext()
1>--- End of stack trace from previous location where exception was thrown ---
1> at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
1> at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
1> at NConsole.CommandLineProcessor.Process(String[] args, Object input)
1> at NSwag.Commands.NSwagCommandProcessor.Process(String[] args) in C:\projects\nswag\src\NSwag.Commands\NSwagCommandProcessor.cs:line 54
1>
From my csproj:
<Target Name="NSwag" AfterTargets="Build">
<Copy SourceFiles="@(Reference)" DestinationFolder="$(OutDir)References" />
<Exec Command="$(NSwagExe_Core20) webapi2swagger /assembly:$(OutDir)$(AssemblyName).dll /output:$(OutDir)swagger.json" />
<Exec Command="$(NSwagExe_Core20) swagger2tsclient /input:$(OutDir)swagger.json /output:$(OutDir)NSwag-Generated/$(AssemblyName).ts" />
<RemoveDir Directories="$(OutDir)References" />
</Target>
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 19 (10 by maintainers)
Looking forward to when NetCore21 can be added. It’s now in preview 2 release (I’m having to use it for EF Core functionality).
Studio can load the DLL and find the controllers, but then I get this error:
I assume with the proper target this will just work, but adding this here so others can find this thread.
Hope to add it soon…