autorest.csharp: Cannot convert from 'System.Net.Http.HttpClient' to 'System.Net.Http.DelegatingHandler'
Having the following issue when trying to build:
2018-09-27T09:03:16.5416142Z FoobarAPI.cs(48,82): error CS1503: Argument 1: cannot convert from 'System.Net.Http.HttpClient' to 'System.Net.Http.DelegatingHandler' [/home/deploy/myagent/_work/42/s/Foobar.API/Foobar.API.csproj]
2018-09-27T09:03:16.5441669Z FoobarAPI.cs(48,94): error CS1503: Argument 2: cannot convert from 'bool' to 'System.Net.Http.DelegatingHandler' [/home/deploy/myagent/_work/42/s/Foobar.API/Foobar.API.csproj]
My build steps:
npm install -g autorest@preview
autorest --reset
autorest --input-file=swagger.json --output-folder=Foobar.API --csharp --preview --namespace=Foobar.API
Line 48:
/// <summary>
/// Initializes a new instance of the FoobarAPI class.
/// </summary>
/// <param name='httpClient'>
/// HttpClient to be used
/// </param>
/// <param name='disposeHttpClient'>
/// True: will dispose the provided httpClient on calling FoobarAPI.Dispose(). False: will not dispose provided httpClient</param>
public FoobarAPI(HttpClient httpClient, bool disposeHttpClient) : base(httpClient, disposeHttpClient)
{
Initialize();
}
ASP.Net Core 2.1
.NET Core SDK (reflecting any global.json):
Version: 2.1.402
Commit: 3599f217f4
Runtime Environment:
OS Name: ubuntu
OS Version: 18.04
OS Platform: Linux
RID: ubuntu.18.04-x64
Base Path: /usr/share/dotnet/sdk/2.1.402/
Host (useful for support):
Version: 2.1.4
Commit: 85255dde3e
.NET Core SDKs installed:
2.1.402 [/usr/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.4 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.4 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.4 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 3
- Comments: 19 (5 by maintainers)
Commenting for benefit of other users after googling this error in dotnet core 2.2…
When you add the Microsoft.Rest.ClientRuntime package, make sure you specify the version just as the nuget page tells you to on the .NET CLI tab. If you omit, it installs V3.something which produces this error.
Run the command as suggested by the .NET CLI tab on the Nuget page for the package:
dotnet add package Microsoft.Rest.ClientRuntime --version 2.3.20
That version works for me, the project with the autorest generated client now builds.
I’m hitting the same problem, but I don’t have the option of upgrading the Microsoft.Rest.ClientRuntime version, since it’s only compatible with .net core.
It started after I upgraded from Autorest 2.0.4166 to 2.0.4283
For now I’m manually removing the new constructor since it wasn’t being used earlier anyway, however, I would have preferred if Autorest could have had a flag for disabling the generation of this constructor for legacy clients.