Skip to content
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

AI (Internal): Unknown error, message System.UriFormatException: Invalid URI: The hostname could not be parsed. #1328

Closed
TimothyMothra opened this issue Nov 25, 2019 · 1 comment
Labels
Milestone

Comments

@TimothyMothra
Copy link
Member

Error:

AI (Internal): [Microsoft-ApplicationInsights-Extensibility-Web] Unknown error, message System.UriFormatException: Invalid URI: The hostname could not be parsed.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Web.Util.UriUtil.BuildUriImpl(String scheme, String serverName, String port, String path, String queryString, Boolean useLegacyRequestUrlGeneration)
at System.Web.HttpRequest.BuildUrl(Func1 pathAccessor)
at System.Web.UnvalidatedRequestValues.get_Url()
at Microsoft.ApplicationInsights.Common.RequestTrackingUtilities.UpdateRequestTelemetryFromRequest(RequestTelemetry requestTelemetry, HttpRequest request, IApplicationIdProvider applicationIdProvider)
at Microsoft.ApplicationInsights.Web.RequestTrackingTelemetryModule.OnEndRequest(HttpContext context)
at Microsoft.ApplicationInsights.Web.AspNetDiagnosticTelemetryModule.AspNetEventObserver.OnNext(KeyValuePair2 value)

Source:

internal static void UpdateRequestTelemetryFromRequest(RequestTelemetry requestTelemetry, HttpRequest request, IApplicationIdProvider applicationIdProvider)
{
if (requestTelemetry == null || request == null)
{
return;
}
if (requestTelemetry.Url == null)
{
requestTelemetry.Url = request.Unvalidated.Url;
}

The getter for the Unvalidated Url is failing to parse and create a Uri object.
Should we wrap this in a try/catch and ignore the Exception?

Internal Call Stack:
https://referencesource.microsoft.com/#System.Web/UnvalidatedRequestValues.cs,144

public sealed class UnvalidatedRequestValues {
    private Uri _url;
    public Uri Url {
        get {
            if (_url == null) {
                _url = _request.BuildUrl(() => Path);
            }
            return _url;
        }
    }

https://referencesource.microsoft.com/#System/net/System/UriExt.cs,32

    private void CreateThis(string uri, bool dontEscape, UriKind uriKind)
    {
        // if (!Enum.IsDefined(typeof(UriKind), uriKind)) -- We currently believe that Enum.IsDefined() is too slow 
        // to be used here.
        if ((int)uriKind < (int)UriKind.RelativeOrAbsolute || (int)uriKind > (int)UriKind.Relative) {
            throw new ArgumentException(SR.GetString(SR.net_uri_InvalidUriKind, uriKind));
        }

        m_String = uri == null? string.Empty: uri;

        if (dontEscape)
            m_Flags |= Flags.UserEscaped;

        ParsingError err = ParseScheme(m_String, ref m_Flags, ref m_Syntax);
        UriFormatException e;

        InitializeUri(err, uriKind, out e);
        if (e != null)
            throw e;
    }
@xperiandri
Copy link

Can't you rewrite that without throwing an exception?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants