question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The format of value xxx is invalid

See original GitHub issue

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

Update 1 I think TextAnalyticsClient tries to set a header key/value and header value is not valid.

Update 2 I see the source of the problem. Its setting OsVersion on header of HttpClient and it’s not url friendly or something and HttpClient is throwing an exception:

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

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
shahabhijeetcommented, Nov 21, 2018

@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

0reactions
santifdezmunozcommented, Feb 24, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding HttpClient headers generates a FormatException ...
System.FormatException : The format of value key=XXX' is invalid. The solution is to remove the equals sign. Digging into reflector ...
Read more >
Adding HttpClient headers generates a FormatException ...
FormatException : The format of value key=XXX' is invalid. The solution is to remove the equals sign. Digging into reflector shows there is...
Read more >
System.FormatException: The format of value 'xxx' is invalid.
System.FormatException : The format of value 'key=xxxxxx' is invalid. at System.Net.Http.Headers.HttpHeaderParser.ParseValue(String value ...
Read more >
[Solved] Httpclient authorization issue
Why HttpClient rejects that exact value with a FormatException, is because it is an invalid Authorization value: valid Authorization values ...
Read more >
MX Record invalid format - Microsoft Community Hub
I have a domain through Google and work email through Microsoft. When I try to add the MX Record from Microsoft to Google,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found