问题
I am developing an Dotnet core 2.x(actually using 2.1.4, latest release when I'm writing this) web api project, in order to use couchbase as my database server, I need to use the couchbase SDK. The sdk states that it supports DotNet core 2.x.
After a very basic setup and I just want to test the connectivity, I keep getting this error.
HttpRequestException: The handler does not support custom handling of certificates with this combination of libcurl (7.54.0) and its SSL backend ("LibreSSL/2.0.20").
I thought this is a issue with the couchbase SDK, but after some research, I found it is about the macOS built-in openssl and curl does not support certain behavior. Here are some reference:
.NET Core, OSX, libcurl, and OpenSSL
Couchbase dotnet SDK OSX libcurl error
after some more research, it turns out that dotnet core 2.0 should no longer suffer from the MacOS related issue...But why am I still getting this?
Is there any workaround like telling HttpClient to use brew version of curl?
回答1:
Steps to Use Socket HTTP Handler
Here's what I needed to do to get this to work:
- Install .NET Core SDK 2.1.xxx-preview
- Update Project
AspNetCore.All
Reference - Add Package Source to
NuGet.Config
- Set Environment Variable
Install .NET Core SDK [2.1.xxx-preview]
Download and install macOs installer
Update Project AspNetCore.All
Reference
Update package reference to:
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0-preview1-final" />
Add Package Source to NuGet.Config
Update ~/.nuget/NuGet/NuGet.Config
and add another package source:
<add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
I needed to do this because I was getting a NuGet error:
error NU1102: Unable to find package Microsoft.AspNetCore.All with version (>= 2.1.0)
.
Set Environment Variable
In my Startup.cs
I set an environment variable:
Environment.SetEnvironmentVariable("DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER", "true");
What We're Doing
With 2.1 dotnet will incorporate its own Socket Handler which bypasses OS specific ones and so we can avoid the macOS issues. In preview-1 we still have to manually opt-in: https://github.com/dotnet/corefx/blob/master/src/System.Net.Http/src/System/Net/Http/HttpClientHandler.cs
But soon in preview-2 it'll be on by default: https://github.com/dotnet/corefx/pull/27821
Previous post
I've been investigating the same issue this morning and I currently don't think there's a clear solution. Dotnet Core 2.x does not resolve the issue for the Couchbase SDK, though I think using HttpClient
outside of Couchbase is fine (haven't tested this).
As of Couchbase SDK Version 2.5.8 (17 March 2018) this is still a known issue: https://developer.couchbase.com/server/other-products/release-notes-archives/dotnet-sdk
Actual issue link: https://issues.couchbase.com/browse/NCBC-1296
In the forums, see:
- https://forums.couchbase.com/t/couchbase-dotnet-sdk-osx-libcurl-error/12238
- https://forums.couchbase.com/t/platformnotsupportedexception-when-querying-from-net-core-2-0-on-macos/15490/6
I'll post back if I find a working solution.
来源:https://stackoverflow.com/questions/48719442/dotnet-core-2-0-on-macos-gets-libcurl-and-ssl-error-triggered-by-httpclient-when