System.UriFormatException : Invalid URI: The hostname could not be parsed. #1481
Comments
From @nulltoken on July 2, 2018 19:9 FWIW this was working against .NET Core 2.0.5 |
Confirmed, this is a bug in TestHost. Minimized repro:
Expected: localhost:12345 The Host is set from the Url here:
But then the request headers are copied over here: Hosting/src/Microsoft.AspNetCore.TestHost/ClientHandler.cs Lines 90 to 93 in 97c9510
This adds an invalid second Host rather than overwriting. Recommendation: |
@Tratcher Would you mind if I tried and gave a try at fixing it? |
Go for it. |
@Tratcher Done. That was indeed a pretty easy fix. You wonderfully paved the way with your detailed explanation. Thanks a lot! The only things that keeps on bugging me is that in my initial repro, not all the tests were failing. Only some of them. Condering that |
I don't have a good answer for that. The error wouldn't happen until the Uri was constructed, and only AI does that. Either that wasn't happening on some requests, or the error was being handled differently on some code paths. |
From @nulltoken on July 2, 2018 12:39
Hello,
It's possible I may have found a bug (or at the very least a surprising behavior 馃槈 ).
Running an integration test, using the TestServer, against an Mvc backed API (monitored by ApplicationInsights), throws a
UriFormatException
.It looks like (cf. the screenshots below) that the host being parsed end up being
"localhost,localhost"
.I've managed to trim down the code as much as possible into a repro case available at https://github.com/nulltoken/UriFormatException
Beware, that looks pretty random. The repro case breaks most of time with one failing test, and from time to time two tests fail.
FWIW, removing this line from the repro case makes the problem disappear.
Versions:
Copied from original issue: aspnet/Mvc#7997
The text was updated successfully, but these errors were encountered: