The format of value xxx is invalid
See original GitHub issueI 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:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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
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.