【问题标题】:azure-sdk-for-net throws an exception on Macazure-sdk-for-net 在 Mac 上引发异常
【发布时间】:2018-11-21 20:01:30
【问题描述】:

我正在尝试将 Azure 文本分析 API SDK 用于 dotnet (basically this nuget package)。我正在使用 Mac。

运行代码时出现以下异常(我使用 Mac):

值“Darwin17.7.0DarwinKernelVersion17.7.0WedOct10230614PDT2018rootxnu-4570.71.131/RELEASE_X86_64”的格式无效。

这是引发异常的代码:

var serviceClientCredentials = new AzureApiKeyServiceClientCredentials("<key>");
// Throw an exception here
var client = new TextAnalyticsClient(_serviceClientCredentials);

ServiceClientCredentials 类:

public class AzureApiKeyServiceClientCredentials : ServiceClientCredentials
{
    private readonly string _subscriptionKey;

    public AzureApiKeyServiceClientCredentials(string subscriptionKey)
    {
        _subscriptionKey = subscriptionKey;
    }

    public override Task ProcessHttpRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        request.Headers.Add("Ocp-Apim-Subscription-Key", _subscriptionKey);

        return base.ProcessHttpRequestAsync(request, cancellationToken);
    }
}

问题根源

在尝试了解源代码后,我发现TextAnalyticsClient 尝试设置标头键/值,并且该值不是有效的 http 标头值(即Darwin..../RELEASE_X86_64)。更具体地说,我在源代码中看到,它在 HttpClient 的标题上设置了 OsVersion,它不是 url 友好的值,HttpClient 正在引发异常:

this.UpdateDefaultUserAgentList("OSVersion", this.OsVersion);

我创建了一个issue on GitHub。所以,他们需要做的就是修复它到always call CleanUserAgentInfoEntry(_osVersion)

我在他们的消息来源中看到他们从new PlatformInfo(); 获得OsVersion,我想知道是否可以更改RuntimeInformation.OSDescription

更新: 我创建了一个pull request 来解决这个问题。

【问题讨论】:

  • 我不明白。当然,您链接到的代码已经 总是已经调用CleanUserAgentInfoEntry_osVersion 是一个私有字段:如果没有设置,该代码会设置它并清除它。什么情况下可以清洗?

标签: c# azure .net-core


【解决方案1】:

我刚刚解决了这个问题,thanks to @shahabhijeet。我安装了最新版本的Microsoft.Rest.ClientRuntime,它解决了这个问题。

GitHub 问题线程:https://github.com/Azure/azure-sdk-for-net/issues/5046

【讨论】:

    猜你喜欢
    • 2016-12-11
    • 1970-01-01
    • 2021-11-06
    • 1970-01-01
    • 1970-01-01
    • 2016-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多