10

All of a sudden I'm getting the following error on my website. It doesn't access a database. It's just a simple website using .NET 2.0.

I did recently apply the available windows server 2003 service packs. Could that have changed things?

I should add that the error randomly comes and goes and has been doing so for today and yesterday. I leave it for 5 minutes and the error is gone.

Server Error in '/' Application.

Invalid URI: The hostname could not be parsed. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:

System.UriFormatException: Invalid URI: The hostname could not be parsed.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[UriFormatException: Invalid URI: The hostname could not be parsed.]
System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind) +5367536 System.Uri.CreateUri(Uri baseUri, String relativeUri, Boolean dontEscape) +31 System.Uri..ctor(Uri baseUri, String relativeUri) +34 System.Net.HttpWebRequest.CheckResubmit(Exception& e) +5300867

[WebException: Cannot handle redirect from HTTP/HTTPS protocols to other dissimilar ones.] System.Net.HttpWebRequest.GetResponse() +5314029 System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials) +69
System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials) +3929371 System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn) +54
System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver) +74
System.Threading.CompressedStack.runTryCode(Object userData) +70
System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) +0
System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state) +108
System.Xml.XmlTextReaderImpl.OpenUrl() +186
System.Xml.XmlTextReaderImpl.Read() +208
System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) +112 System.Xml.XmlDocument.Load(XmlReader reader) +108
System.Web.UI.WebControls.XmlDataSource.PopulateXmlDocument(XmlDocument document, CacheDependency& dataCacheDependency, CacheDependency& transformCacheDependency) +303
System.Web.UI.WebControls.XmlDataSource.GetXmlDocument() +153
System.Web.UI.WebControls.XmlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +29 System.Web.UI.WebControls.BaseDataList.GetData() +39 System.Web.UI.WebControls.DataList.CreateControlHierarchy(Boolean useDataSource) +264
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +55 System.Web.UI.WebControls.BaseDataList.DataBind() +75
System.Web.UI.WebControls.BaseDataList.EnsureDataBound() +55
System.Web.UI.WebControls.BaseDataList.CreateChildControls() +65
System.Web.UI.Control.EnsureChildControls() +97
System.Web.UI.Control.PreRenderRecursiveInternal() +53
System.Web.UI.Control.PreRenderRecursiveInternal() +202
System.Web.UI.Control.PreRenderRecursiveInternal() +202
System.Web.UI.Control.PreRenderRecursiveInternal() +202
System.Web.UI.Control.PreRenderRecursiveInternal() +202
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4588

CDspace
  • 2,639
  • 18
  • 30
  • 36
Shane
  • 101
  • 1
  • 1
  • 3
  • Please show us your `XmlDataSource`. – SLaks May 11 '10 at 22:48
  • hmm.. the only xml in the site is in an xml file used for a RadRotator (telerik). But that's not been changed in ages. The only other thing is the web.config file. – Shane May 11 '10 at 22:52
  • This stack trace is from a DataList bound to an XmlDataSource. – SLaks May 11 '10 at 22:53
  • Scratch the radrotator error, since the error showed up on pages that didnt have it also. – Shane May 11 '10 at 22:54
  • ah, you're right. that is what it says. Trouble is there are no datalists unless it's part of a telerik control. I cant see anything to narrow down where exactly the error originiated. can you? – Shane May 11 '10 at 22:57
  • Scratch that. there is a datalist that I use to display an rss feed. It hasnt changed in eons. I'll dig down that path. – Shane May 11 '10 at 23:11
  • (PubDate)

    – Shane May 11 '10 at 23:11
  • ill surround it in a try/catch and watch the errors. obviously should have had some error handling already inthere. thanks a lot for pointing me in the right direction!!! – Shane May 11 '10 at 23:13
  • Please show us the `RssData` source. – SLaks May 11 '10 at 23:25

1 Answers1

6

There are some bugs in Uri.Create and Uri.TryCreate that allow them to create invalid URIs that cannot subsequently be parsed. I've run into this from time to time, but have been unable to track down the url strings that cause it. I posted a little bit about it here.

If you have a list of urls and know that one of them causes the problem (I didn't have that luxury, as I encountered this in a Web crawl where I wasn't saving the page text), you can find the error with something like this pseudocode:

while not end of file
{
    string url = read from file
    Uri uri = new Uri(url);
    try
    {
        string host = uri.Host;
    }
    catch (UriFormatException)
    {
        Console.WriteLine("Bad url: {0}", url);
    }
}

If you can identify some urls that cause this exception, I'd sure like to see them.

Community
  • 1
  • 1
Jim Mischel
  • 131,090
  • 20
  • 188
  • 351
  • Try this string: "mailto:foo[at]bar.com" – huseyint Apr 24 '14 at 13:42
  • 1
    @huseyint: The strings `"foo@bar.com"` works as expected. The string `"foo[at]bar.com"` throws an exception in the constructor, again as expected. The error I encountered was with strings for which the `Uri` constructor succeeds, but subsequent access of the `Host` property throws an exception. – Jim Mischel Apr 24 '14 at 13:55