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.

Remove comment only ProductInfoHeaderValue

See original GitHub issue

Version

all, but particularly 4.11.+

Describe the bug

In 4.11, we have added a constructor to ConnectorClient which takes an HttpClient. We then pass that HttpClient down to the underlying ServicClient’s constructor. Due to the fact that we have a ProductInfoHeaderValue which has no Product (comment only), the underlying ServiceClient will throw and catch 4 exceptions.

I’ve created a PR to address this within ServiceClient, but they have recommended we remove the comment only ProductInfoHeaderValue: https://github.com/Azure/azure-sdk-for-net/pull/16252

To Reproduce

Steps to reproduce the behavior: Run this test:

        [Fact]
        public void ConnectorClient_CustomHttpClient_UserAgentHeaderAdds()
        {
            var httpClient = new HttpClient();
            ConnectorClient.AddDefaultRequestHeaders(httpClient);

            using (var connector = new ConnectorClient(new Uri("http://localhost/"), new MicrosoftAppCredentials(string.Empty, string.Empty), customHttpClient: httpClient, disposeHttpClient: false))
            {
                // Use the connector
            }

            Assert.Equal(6, httpClient.DefaultRequestHeaders.UserAgent.Count);
        }

Notice, none of the ServiceClient UserAgent headers have been added.

Expected behavior

Underlying ServiceClient UserAgent headers are added.

Remove the comment only product info header, and re-run the above test. It will pass. https://github.com/microsoft/botbuilder-dotnet/blob/main/libraries/Microsoft.Bot.Connector/ConnectorClientEx.cs#L200

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
EricDahlvangcommented, Nov 4, 2020

The recommendation for anyone seeing a null reference exception due to this is to ignore.

1reaction
EricDahlvangcommented, Dec 9, 2020

Hi @sebnema

I’m sorry you’ve spent time investigating this. The root cause is a known issue. You are correct, that the problem is in ServiceClient and has been present for years now. They are apprehensive to take a fix at this level of the core product: https://github.com/Azure/azure-sdk-for-net/pull/16252

The reason the Bot Builder sdk has not had this issue until 4.11.0 is because we were not using the ServiceClient constructor with HttpClient param, until 4.11.0: https://github.com/microsoft/botbuilder-dotnet/commit/918c54778e0c0e48187560661f208e034ceffb31#diff-914b91edd6e7e20fb74559dea5488a0b0ee7d63a197cd703135fb1adf44d079a

Our plan to resolve this in 4.12.0 is to replace the comment only ProductInfoHeaderValue in the Bot Builder SDK with one containing a product.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove server header in self hosted WebApi response
There is no code solution to remove Server HTTP header on self host. The only solution is to edit windows registry: ...
Read more >
c# - Universal app HttpClient header: how to disable some ...
A bit of background: I'm trying to "port" an android app to Windows Phone that calls a non-open web API. Since the API...
Read more >
ProductInfoHeaderValue.Comment Property (System.Net. ...
Gets the comment from the ProductInfoHeaderValue object.
Read more >
ProductInfoHeaderValue, System.Net.Http.Headers C# ...
Http.Headers ProductInfoHeaderValue - 42 examples found. ... Caller must remove leading whitespace. string? comment = null; ProductHeaderValue?product ...
Read more >
HttpRequestHeadersTest.cs
Contains("User-Agent"), "User-Agent header should be removed after calling Clear().");; headers.UserAgent.Add(new ProductInfoHeaderValue("(comment)")); ...
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