Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
.NET 2 introduced a 'UriParser'  class which is used by System.Uri to parse strings into Uri objects. Our current implementation of System.Uri completely ignores this infrastructure and does all the parsing inside the Uri class itself. As such, it is impossible to define custom Uri schemes and have them parsed successfully.
Our System.IO.Packaging API requires this support to function correctly. We've been limping along for the last few years with some hacks internally to allow very very basic PackUri support, but we have dozens of failing tests  which need fixing. I believe the PackUriParser I implemented will work once System.Uri uses the UriParser infrastructure, but it might need some tweaking too.
We should explore the UriParser implementation.
We recently rewrote the Uri class to drop its dependency on Regex, since that brings the world on mobile devices. We should not regress when we go down the UriParser path.
If I remember correctly, there's a lot more brokenness in the Uri class, for instance we don't support the new unicode domain names that were introduced by MS in .NET 4.0 and I also think we don't always properly escape things.
Which means that class needs some love and using UriParser may be a good idea.
However, I'm not sure about that Regex problem that Miguel mentioned.
I can explain.
Our version of Uri used to use a System.Text.RegularExpressions.Regex to parse a URI, which was probably very easy for a first implementation but had the downside of being difficult to extend but most importantly, it meant that even using "Uri" for a simple task would bring Regex and all of its depending classes. For mobile applications that was a lot of code.
So we rewrote it a few months ago to have a pure parser that does not depend on Regex.
If we decide to move to UriParser, we should make sure that UriParser does not use Regex either to shortcut things.
I would assume most of the work will be stripping the code out of Uri.cs and putting it in the various UriParser subclasses which are in the BCL. These are the subclasses in the BCL:
We have tests for at least some of these subclasses and some of those tests are marked as [Category ("NotWorking")] too. Ideally those tests would need to be fixed and enabled as part of this.
I tried to look into the IPv6-related problems of the Uri class - and well, it really needs a lot of love.
In addition to using the UriParser infrastructure, it should use use the parser for IsWellFormedOriginalString() and IsWellFormedUriString().
The following pull request adds correct use of registered scheme parser, which fixes most of the disabled tests.
The remaining disabled tests can be fixed by adding to PackUriHelper methods validation code that throws expected exceptions.
Once the pull request 1168 is accepted I will add the validation code and enable all the PackUriHelperTests tests.
The pull request for this issue can be found in the link below.
Fixed in master ed065cd04dbf3686033f6474946c40d49ad424b1.