Ошибка hostname could not be parsed

Back from my weekend and went to debug my web project which is an ASP.NET Core Web Api. It started giving me an error: Invalid URI: The hostname could not be parsed.

I can start a new asp.net core web api project and it debugs fine so I’m pretty sure its something with my configuration for this project. Any ideas?

James

asked Mar 14, 2017 at 14:59

James Scott's user avatar

1

Solution:

  1. Close Visual Studio
  2. Remove .vs folder

Fixed:)

answered May 15, 2017 at 14:37

szubajak's user avatar

szubajakszubajak

4267 silver badges12 bronze badges

4

I post this answer because many people found my comment useful. Thanks to @joshcomley for poking me.

Hopefully this answer will help someone:

  1. In your solution folder find subfolder named .vs (note, this folder has a hidden attribute, so File Explorer does not show it by default)
  2. Open .vs/config/applicationhost.config file
  3. Inside the file find element like <site name="<Your_Web_Site_Name>" ..... You can have several elements like this. You need to pick one where <Your_Web_Site_Name> matches the name of your site
  4. Inside <site element find a child element like:

<binding protocol="http" bindingInformation=":8080:localhost" />

and replace it with:

<binding protocol="http" bindingInformation=":8080:" />

  1. Rebuild solution and Run website

Notes:

  • The port number 8080 is given as an example. You should assign the port that you actually use for the website.
  • This fix works for websites hosted in IISExpress. It also allows to avoid error message like Invalid URI: The hostname could not be parsed.
  • If your website is using IIS, you may try to replace binding with this line:
    <binding protocol="http" bindingInformation="*:8080:*" />. And do iisreset after this change.

answered Feb 21, 2018 at 7:45

VeganHunter's user avatar

VeganHunterVeganHunter

5,5242 gold badges25 silver badges25 bronze badges

3

I was having the same issue and tried other suggestions in this post, but it didn´t work. So I went to Properties of the project -> Debug -> WebServer Settings
There I´ve replaced the * with localhost and that solved the issue for me.
Properties capture

answered May 20, 2020 at 8:33

Javier Pazos's user avatar

1

Jakub’s answer does fix the issue because it causes Visual Studio to regenerate applicationhost.config. In my case, the error was saying that the value of the <binding> tag could not be parsed. I had the following:
<binding protocol="http" bindingInformation="*:5000:*" />
which when regenerated looked like this:
<binding protocol="http" bindingInformation="*:5000:localhost" />
The file is found inside the «.vs» folder’s «config» subfolder, and instead of deleting the whole directory, you can just fix/restore your <binding> tag to a value that can be parsed.

Edit: per @VeganHunter’s comment, * is not a valid hostname. If you want it to bind to all hostnames just leave the host blank. Ex: *:80: instead of *:80:* means «All network interfaces/IPs, on port 80, for all hostnames».

answered Jun 27, 2017 at 17:14

QuickDanger's user avatar

QuickDangerQuickDanger

1,03211 silver badges18 bronze badges

2

This error indicates that your bindingInformation for the site is not in the correct format.

The value for bindingInformation consists of three parts.

ip:port:host

Here are some formats of bindings and their result:

<!-- Configures the site with a hostname of "www.test.com" on port 80 for the IP address of 192.168.1.10. -->
<binding protocol="http" bindingInformation="192.168.1.10:80:www.test.com" />

<!-- Configures the site with a hostname of "localhost" on port 80 for the IP address of 192.168.1.10. -->
<binding protocol="http" bindingInformation="192.168.1.10:80:localhost" />

<!-- Configures the site without a hostname and IP address on port 80. You'd use this setting to make your site directly accessible via any address that the system has, including the localhost address at 127.0.0.1, as well as any and all configured IP addresses. -->
<binding protocol="http" bindingInformation=":80:" />

<binding protocol="https" bindingInformation="*:443:" />
<!-- Configures HTTPS bindings for all IP addresses over port 443. -->

With all the above bindings, you can set the protocol to https to make your site accessible only through SSL.

answered Feb 16, 2018 at 12:20

chaosifier's user avatar

chaosifierchaosifier

2,63624 silver badges39 bronze badges

My answer is a variant from @Javier Pazos

In my case, going to the the project properties, my URI was correct,
enter image description here

However, my Environment Variables were wrong (this happened after updating VS)
enter image description here

So, here replace the «*» for localhost

answered Nov 9, 2022 at 22:02

DReact's user avatar

DReactDReact

5365 silver badges6 bronze badges

I was getting similar issue and running the Visual Studio in Administrator mode resolved the issue for me.

answered Aug 19, 2019 at 15:27

Ayush's user avatar

AyushAyush

4752 gold badges5 silver badges18 bronze badges

I recently came across this issue. I tried to use the drive mapping workaround like @drwatson85 mentioned. This issue went away; however, I started encountering other issues. Odd issues.

The visual studio IDE compiler was not keeping up with my changes. Like i’ll add a public property on a class and i was unable to reference that property in another file. It was saying the property didn’t exist. I was able to do a compile just fine though.

Also the «Errors» window would not update when there was a valid compilation error. I removed a public static from a static class and it was properly failing the build, but the errors was not showing anything. I had to look at the output to see what was hte issue.

And finally, while debugging a unit test it would complain that the source was modified and i could either stop the debug or edit. I didn’t make any changes to the source file at all, and git was not detecting any code changes either.

These issues are in regards to Visual Studio 2019 Professional, version Version 16.10.0. Also these oddities were appeaing in our unit test project which had project references to the main code. The unit test project is using:

  • NUnit 3.16.1
  • NUnit3TestAdapter 3.16.1
  • Microsoft.NET.Test.Sdk 16.5.0
  • Remove From My Forums
  • Question

  • Hi,

    when I am running my LOB Adapter, I am getting an error at public override Uri Uri, in my AdapterConnectionUri class.

    Error isTongue Tiedystem.UriFormatException was unhandled by user code
      Message=»Invalid URI: The hostname could not be parsed
      Source=»System»
      StackTrace:
           at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
           at System.Uri..ctor(String uriString)
           at Mphasis.Adapters.AD.ADAdapterConnectionUri.get_Uri() in C:TFSApplication EngineeringWCF AdapterPOCPracticeWCF LOB AdapterADAdapterADAdapterADAdapterConnectionUri.cs:line 112
           at Microsoft.ServiceModel.Channels.Common.ConnectionUri.get_SecureUriString()
           at Microsoft.ServiceModel.Channels.Common.Channels.AdapterChannelFactory`1.GetConnectionPool(ConnectionUri connectionUri, String uriString)

    and my public override Uri Uri looks as follows:

    Code Snippet

    public override Uri Uri

    {

    get

    {

    //

    //TODO: Return the composed uri in valid format

    //

    //throw new NotImplementedException(«The method or operation is not implemented.»);

    // Build the uri

    if (String.IsNullOrEmpty(this.server)) throw new InvalidUriException(«Invalid target system Server.»);

    if (String.IsNullOrEmpty(this.domain)) throw new InvalidUriException(«Invalid target system Domain.»);

    // build the uri

    return new Uri(ADAdapter.SCHEME + «://» + this.Server + «;» + this.Domain + «?» + «enableAuthentication=» + EnableAuthentication);

    }

    set

    {

    //

    //TODO: Parse the uri into its relevant parts to produce a valid Uri object. (For example scheme, host, query).

    //

    //throw new NotImplementedException(«The method or operation is not implemented.»);

    // Parse the uri

    String[] enableAuthValue = GetQueryStringValue(value, «enableAuthentication»);

    if (enableAuthValue.Length > 0) this.enableAuthentication = Boolean.Parse(enableAuthValue[0]);

    this.server = value.Host;

    String[] applicationValue = value.AbsolutePath.Split(‘/’);

    if (applicationValue.Length > 1) this.domain = applicationValue[1];

    }

    }

    I am getting error at this line :

    return new Uri(ADAdapter.SCHEME + «://» + this.Server + «;» + this.Domain + «?» + «enableAuthentication=» + EnableAuthentication);

    can any one help out in solving this error.

    Thanks,

Answers

  • The hostname in your URI turns out to be

    this.Server + «;» + this.Domain

    which is not valid due to the «;» character. The Uri you create should be System.Uri compliant. You can check out http://msdn.microsoft.com/en-us/library/system.uri.aspx

    You can use UriBuilder class to create your URI.

Symptoms

On a Windows Embedded CE 6.0-based device, a managed application exits abnormally when you use a WebBrowser control. Additionally, you receive the following error message:


Invalid URI: The hostname could not be parsed.

This problem occurs when the following conditions are true:

  • The WebBrowser control tries to trigger a navigating event in response to a navigation request.

  • The request contains a URL that references a Web page that is stored in a local resource dynamic link library (DLL).

Cause

This problem occurs because the logic of the .NET Compact Framework URL parser that validates a URL does not recognize the format of the URL that the request contains. The logic is used by the Uniform Resource Identifier (URI) class.

Resolution

Software update information

A supported software update is now available from Microsoft as Windows CE 6.0 Platform Builder Monthly Update (September 2009). You can confirm this by scrolling to the «File information» section of this article. The package file name contains the product version, date, Knowledge Base article number, and processor type. The package file name format is:

Product version-yymmdd-kbnnnnnn-processor typeFor example: Wincepb50-060503-kb917590-armv4i.msi is the ARMV4i Windows CE 5.0 Platform Builder fix that is documented in KB article 917590 and that is contained in the May 2006 monthly update. To resolve this problem immediately, click the following article number for information about obtaining Windows CE Platform Builder and core operating system software updates:

837392 How to locate core operating system fixes for Microsoft Windows CE Platform Builder products

Prerequisites

This update is supported only if all previously issued updates for this product are installed.

Restart requirement

After you apply this update, you must perform a clean build of the whole platform. To do this, use one of the following methods:

  • On the Build menu, click Clean, and then click Build Platform.

  • On the Build menu, click Rebuild Platform.

You do not have to restart the computer after you apply this update.

Update replacement information

This update does not replace any other updates.

File information

The English version of this software update package has the file attributes (or later file attributes) that are listed in the following table. The dates and times for these files are listed in Coordinated Universal Time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time item in Control Panel.

File name

File size

Date

Time

Windows embedded ce 6.0_update_kb976213.htm

6,546

30-Sep-2009

20:04

Wincepb60-090930-kb976213-common.msi

611,840

30-Sep-2009

20:45

File name

File size

Date

Time

Path

System.dll

526,504

26-Sep-2009

00:56

OthersDotnetv35Managed

Workaround

To work around this problem, set the value of the Friendly http errors registry entry to no. The registry is under the HKEY_CURRENT_USERSoftwareMicrosoftInternet ExplorerMain registry subkey.

Status

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the «Applies to» section.

More Information

When a server sends an error response code, the native Web browser components may move to a Web page that is stored in a local resource DLL. When this behavior occurs, the resulting URL starts with the «HTTP://Windowsshdoclc.dll/» string.

For more information about software update terminology, click the following article number to view the article in the Microsoft Knowledge Base:

824684 Description of the standard terminology that is used to describe Microsoft software updates

Call stack information

at System.Uri.CreateThis() at System.Uri.ctor() at System.Windows.Forms.WebBrowser.WnProc() at System.Windows.Forms.Control._InternalWnProc() at Microsoft.AGL.Forms.EVL.EnterMainLoop() at System.Windows.Forms.Application.Run() 

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

It’s not a normal behavior.

If you look at the error message, you can see that problem is related to:

System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)

It meant that when any block tries to send request to Sitecore via SitecoreConnectionManager, and
SitecoreConnectionManager processes request via SitecoreConnectionManager.ProcessRequest and couldn’t create Uri:

SitecoreConnectionPolicy policy = commerceContext.GetPolicy<SitecoreConnectionPolicy>();
Uri address = new Uri(string.Format("https://{0}", (object) policy.Host));

From the first look it must works correctly, but…not…

Why do you see this error?

Commerce Engine OOTB has AdventureWorks, Habitat, any your custom environment(s) and … Global environment

Engine tries to send request and get any item from Sitecore, but commerceContext has Environment property which is set to GlobalEnvironment.

If you will open Global.json file you will see that SitecoreConnectionPolicy is missing for GlobalEnvironment and for sure policy.Host is equal null.

How to fix it?

You need to copy and paste configuration below to Global.json file to Policies list:

{
        "$type": "Sitecore.Commerce.Plugin.Management.SitecoreConnectionPolicy, Sitecore.Commerce.Plugin.Management",
        "Host": "{hostname.com}",
        "SitecoreDatabase": "master",
        "UserName": "admin",
        "Domain": "sitecore",
        "Password": "b",
        "ConnectionLeaseTimeout": 60000,
        "AuthRequestUrl": "sitecore/api/ssc/auth/login",
        "Protocol": "https"
}

You need to change Host, UserName, Password base on your configuration.
Also you can find your existing configuration in PlugIn.Content.PolicySet-1.0.0.json file and copy it to Global.json file.

After that you need to Bootstrap engine and restart apppool or iis.

This fix I checked on Sitecore Commerce 9 Update-1.

In Sitecore Commerce 9 Update-2 was added additional check:

        SitecoreConnectionPolicy policy = commerceContext.GetPolicy<SitecoreConnectionPolicy>();
        if (string.IsNullOrEmpty(policy?.Host))
        {
          commerceContext.Logger.LogError(string.Format("SitecoreConnectionManager: SitecoreConnectionPolicy for {0} is missing the host configuration", (object) commerceContext.Environment.Name), Array.Empty<object>());
          return (HttpResponseMessage) null;
        }
        Uri address = new Uri(string.Format("https://{0}", (object) policy.Host));

Which is more informative

Понравилась статья? Поделить с друзьями:
  • Ошибка hdd на видеорегистраторе rvi
  • Ошибка hdd на видеорегистраторе hiwatch
  • Ошибка hdd видеорегистратора
  • Ошибка hdd raw copy
  • Ошибка hdd hikvision