NSwag: System.InvalidOperationException: The ConfigureServices method must either be parameterless or take only one parameter

Have an ASP.NET CORE 2.1 project. I have already read https://github.com/RSuter/NSwag/wiki/Assembly-loading and added this to my project:

  <PropertyGroup>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  </PropertyGroup>

After trying to execute the command:

12.0.12\tools\Win>nswag.exe aspnetcore2swagger /assembly:F:\Test\MyProject.dll /runtime:Net
Core21 /output:swagger.json

First time got an error: System.IO.FileLoadException: Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies.

It has been fixed by installation package System.Diagnostics.DiagnosticSource (newer version than 4.0.3.0).

After that an error occurred: system.invalidoperationexception: unable to resolve service for type 'microsoft.extensions.configuration.iconfiguration' while attempting to activate Startup.

This is a very strange. But I tried to install the package Microsoft.Extensions.DependencyInjection explicitly and it fixed it.

The next error is: System.InvalidOperationException: The ConfigureServices method must either be parameterless or take only one parameter of type IServiceCollection. And I don’t know what to do with this. My ConfigureServices has only one param: public void ConfigureServices(IServiceCollection services).

I spent a lot of time, tried to create a new Core 2.1 project from VS2017 template and got the same errors.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 19 (5 by maintainers)

Most upvoted comments

Thank you @paillave. At the end I made it work by tweaking “/project:pathto.csproj /noBuild:true” approach

For me this helped:

Use /project:pathto.csproj /noBuild:true

Instead of /assembly

Use /project:pathto.csproj /noBuild:true