Bug 21571 - Uri.GetComponents should allow UriComponents.SerializationInfoString on relative Uri
Summary: Uri.GetComponents should allow UriComponents.SerializationInfoString on relat...
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 3.4.0
Hardware: All All
: --- normal
Target Milestone: Untriaged
Assignee: marcos.henrich
URL: https://github.com/mono/mono/pull/1175
Depends on:
Reported: 2014-07-24 11:12 UTC by Chris Eldredge
Modified: 2014-09-08 11:48 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Chris Eldredge 2014-07-24 11:12:35 UTC
System.Uri.GetComponents() fails with InvalidOperationException when Uri.IsAbsoluteUri is false.

Despite MSDN documentation omitting this special case, the .NET BCL allows this method to be invoked on relative Uri instances in the case that the requested component is UriComponents.SerializationInfoString.

This discrepancy prevents portions of Microsoft.AspNet.WebApi.OData from working on Mono in OWIN self-hosted applications.

Related discussion: http://social.msdn.microsoft.com/Forums/en-US/2efaaba5-92cb-4ad4-97da-1216d495a295/bug-uriutilsensureescapedrelativeuri-fails-on-mono

Example stack trace:

System.InvalidOperationException: This operation is not supported for a relative URI.
  at System.Uri.EnsureAbsoluteUri ()
  at System.Uri.get_Scheme ()
  at System.Uri.get_Parser ()
  at System.Uri.GetComponents (UriComponents components, UriFormat format)
  at Microsoft.Data.OData.UriUtils.EnsureEscapedRelativeUri (System.Uri uri)
  at Microsoft.Data.OData.Atom.ODataAtomSerializer.UriToUrlAttributeValue (System.Uri uri, Boolean failOnRelativeUriWithoutBaseUri)
  at Microsoft.Data.OData.Atom.ODataAtomSerializer.UriToUrlAttributeValue (System.Uri uri)
  at Microsoft.Data.OData.Atom.ODataAtomServiceDocumentSerializer.WriteServiceDocument (Microsoft.Data.OData.ODataWorkspace defaultWorkspace)
  at Microsoft.Data.OData.Atom.ODataAtomOutputContext.WriteServiceDocumentImplementation (Microsoft.Data.OData.ODataWorkspace defaultWorkspace)
  at Microsoft.Data.OData.Atom.ODataAtomOutputContext.WriteServiceDocument (Microsoft.Data.OData.ODataWorkspace defaultWorkspace)
  at Microsoft.Data.OData.ODataMessageWriter+<>c__DisplayClass1b.<WriteServiceDocument>b__1a (Microsoft.Data.OData.ODataOutputContext context)
  at Microsoft.Data.OData.ODataMessageWriter.WriteToOutput (ODataPayloadKind payloadKind, System.Action verifyHeaders, System.Action`1 writeAction)
  at Microsoft.Data.OData.ODataMessageWriter.WriteServiceDocument (Microsoft.Data.OData.ODataWorkspace defaultWorkspace)
  at System.Web.Http.OData.Formatter.Serialization.ODataWorkspaceSerializer.WriteObject (System.Object graph, System.Type type, Microsoft.Data.OData.ODataMessageWriter messageWriter, System.Web.Http.OData.Formatter.Serialization.ODataSerializerContext writeContext)
  at System.Web.Http.OData.Formatter.ODataMediaTypeFormatter.WriteToStream (System.Type type, System.Object value, System.IO.Stream writeStream, System.Net.Http.HttpContent content, System.Net.Http.Headers.HttpContentHeaders contentHeaders)
  at System.Web.Http.OData.Formatter.ODataMediaTypeFormatter.WriteToStreamAsync (System.Type type, System.Object value, System.IO.Stream writeStream, System.Net.Http.HttpContent content, System.Net.TransportContext transportContext, CancellationToken cancellationToken)
Comment 1 Chris Eldredge 2014-08-04 08:29:18 UTC
I put this in the URL field but want to make sure it's clear I've proposed a fix in https://github.com/mono/mono/pull/1175
Comment 2 marcos.henrich 2014-08-04 09:53:52 UTC
Hi Chris,

Thanks for reporting the bug for the precise test case and pull request.

I posted a reply in your PR.
Comment 3 marcos.henrich 2014-09-08 10:34:51 UTC
The pull request for this issue can be found in the link below.
Comment 4 marcos.henrich 2014-09-08 11:48:09 UTC
Fixed in master 27b3636cef92e3a8cb154d91e3e7abb9fafea0af.