-
Notifications
You must be signed in to change notification settings - Fork 494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception thrown when application name contains certain characters #3040
Comments
The ApplicationName value is used on the Headers. The validation that you are seeing is not being done by the SDK:
It means the value you are passing is invalid as an HTTP header and it's being validated by the framework ( |
We cannot do the validation before because we (SDK library) does not own the validation. Furthermore, this validation and limitation is done on HTTP requests by the System.Net namespace (HttpClient). This is not a limitation on the TCP requests which is the area we own on the SDK. |
OK, I understand now. What about a try catch around each header.Add() call (or around all of the calls collectively), and in the catch, return friendly string "Adding header "X" <example: ApplicationName" failed. Even that would have be better than current state. In this case, you are not owning the validation but are helping the developer isolate where the issue is to fix it. |
Cosmos .net package 3.24.0
When using the following code
CosmosClient cClient = new CosmosClient(CosmosEndpointUri, CosmosPrimaryKey, new CosmosClientOptions() { ApplicationName = MethodBase.GetCurrentMethod().DeclaringType.Name });
And the method "MethodBase.GetCurrentMethod().Name" is returning the following string:
<Run>d__9
There is a generic exception thrown...
System.FormatException: The format of value '6.0.0-rc.2.21480.5|N|d__9' is invalid.
at System.Net.Http.Headers.HttpHeaderParser.ParseValue(String value, Object storeValue, Int32& index)
at System.Net.Http.Headers.HttpHeaders.ParseAndAddValue(HeaderDescriptor descriptor, HeaderStoreItemInfo info, String value)
at System.Net.Http.Headers.HttpHeaders.Add(HeaderDescriptor descriptor, String value)
at System.Net.Http.Headers.HttpHeaders.Add(String name, String value)
at Microsoft.Azure.Documents.HttpClientExtension.AddUserAgentHeader(HttpClient httpClient, UserAgentContainer userAgent)
at Microsoft.Azure.Cosmos.CosmosHttpClientCore.CreateHelper(HttpClient httpClient, HttpMessageHandler httpMessageHandler, TimeSpan requestTimeout, UserAgentContainer userAgentContainer, ApiType apiType, ICommunicationEventSource eventSource)
at Microsoft.Azure.Cosmos.CosmosHttpClientCore.CreateWithConnectionPolicy(ApiType apiType, ICommunicationEventSource eventSource, ConnectionPolicy connectionPolicy, HttpMessageHandler httpMessageHandler, EventHandler
1 sendingRequestEventArgs, EventHandler
1 receivedResponseEventArgs)at Microsoft.Azure.Cosmos.DocumentClient.Initialize(Uri serviceEndpoint, ConnectionPolicy connectionPolicy, Nullable
1 desiredConsistencyLevel, HttpMessageHandler handler, ISessionContainer sessionContainer, Nullable
1 enableCpuMonitor, IStoreClientFactory storeClientFactory, TokenCredential tokenCredential)at Microsoft.Azure.Cosmos.DocumentClient..ctor(Uri serviceEndpoint, AuthorizationTokenProvider cosmosAuthorization, EventHandler
1 sendingRequestEventArgs, ConnectionPolicy connectionPolicy, Nullable
1 desiredConsistencyLevel, JsonSerializerSettings serializerSettings, ApiType apitype, EventHandler1 receivedResponseEventArgs, HttpMessageHandler handler, ISessionContainer sessionContainer, Nullable
1 enableCpuMonitor, Func`2 transportClientHandlerFactory, IStoreClientFactory storeClientFactory)at Microsoft.Azure.Cosmos.ClientContextCore.Create(CosmosClient cosmosClient, CosmosClientOptions clientOptions)
at Microsoft.Azure.Cosmos.CosmosClient..ctor(String accountEndpoint, AuthorizationTokenProvider authorizationTokenProvider, CosmosClientOptions clientOptions)
at Microsoft.Azure.Cosmos.CosmosClient..ctor(String accountEndpoint, String authKeyOrResourceToken, CosmosClientOptions clientOptions)
at D365SDKAccess.ParallelBatchExecuteMultipleEntityInsert.Run(HttpRequestMessage req, ILogger log) in C:\src\DOD Projects\ATEC\Azure Functions\D365SDKAccess\ParallelBatchExecuteMultipleEntityInsert.cs:line 77
I had to scratch my head for too long to figure out what the issue was. Ideally, a CosmosException would be thrown instead that stated that the application name was invalid (or the code handling the HTTP requests would handle this edge case).
The text was updated successfully, but these errors were encountered: