Azure-sdk-for-net: The format of value xxx is invalid

Created on 21 Nov 2018  路  6Comments  路  Source: Azure/azure-sdk-for-net

I get the following exception when I run the code (I use Mac):

The format of value 'Darwin17.7.0DarwinKernelVersion17.7.0WedOct10230614PDT2018rootxnu-4570.71.131/RELEASE_X86_64' is invalid.

Code that throws an exception

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

    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);
        }
    }



md5-7a07f2e12a31cbd154e3545d01238e33



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

So all you need to do it to fix it is to always call CleanUserAgentInfoEntry(_osVersion).

Most helpful comment

@amir734jj @bastisk can you tell me what version of ClientRuntime are you using in your app?
If you upgrade your app to the latest ClientRuntime, you should not see this issue.
https://www.nuget.org/packages/Microsoft.Rest.ClientRuntime/2.3.18

All 6 comments

Hi together,
I got the same problem running AzureSearch SDK on MacOS. This one appears when creating a new SearchServiceClient.

SearchServiceClient serviceClient = new SearchServiceClient(searchServiceName, new SearchCredentials(adminApiKey));

This produces the following stacktrace

System.FormatException: The format of value 'Darwin18.2.0DarwinKernelVersion18.2.0FriOct5194149PDT2018rootxnu-4903.221.22/RELEASE_X86_64' is invalid.
   at System.Net.Http.Headers.HeaderUtilities.CheckValidToken(String value, String parameterName)
   at System.Net.Http.Headers.ProductHeaderValue..ctor(String name, String version)
   at Microsoft.Rest.ServiceClient`1.UpdateDefaultUserAgentList(String headerName, String headerValue)
   at Microsoft.Rest.ServiceClient`1.get_DefaultUserAgentInfoList()
   at Microsoft.Rest.ServiceClient`1.InitializeHttpClient(HttpClient httpClient, HttpClientHandler httpClientHandler, DelegatingHandler[] handlers)
   at Microsoft.Azure.Search.SearchServiceClient..ctor(String searchServiceName, SearchCredentials credentials)
   ...

Environment
Systemversion: macOS 10.14.1 (18B75)
Kernel-Version: Darwin 18.2.0
Dotnet-Version: 2.1.301
Package Reference: <PackageReference Include="Microsoft.Azure.Search" Version="5.0.3" />

Let's see if the pull request by Amir provides the fix 馃憤

@amir734jj @bastisk can you tell me what version of ClientRuntime are you using in your app?
If you upgrade your app to the latest ClientRuntime, you should not see this issue.
https://www.nuget.org/packages/Microsoft.Rest.ClientRuntime/2.3.18

@shahabhijeet Thanks for the help. I just installed the latest version of Microsoft.Rest.ClientRuntime and it solved the problem.

@amir734jj closing the issue as well as the PR.

I had the same on macOS with the Microsoft.Azure.EventGrid SDK (v3.0.0). It crashed on initialising the client:

var client = new EventGridClient(topicCredentials);

Adding the latest Microsoft.Rest.ClientRuntime (v2.3.19) fixed it as well for me. Perhaps it's useful info for others in the future.

I got the same issue working with Microsoft.Azure.Batch on MacOS Mojave and crashed on the same scenario:

BatchClient batchClient = BatchClient.Open(batchCredentials)

Adding latest Microsoft.Rest.ClientRuntime also fixed the issue for me.

Was this page helpful?
0 / 5 - 0 ratings