Bug 6602 - PackagePart.LoadRelationships makes relative PakcageRelationship target uris absolute
Summary: PackagePart.LoadRelationships makes relative PakcageRelationship target uris ...
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: WindowsBase ()
Version: 2.10.x
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-08-19 13:29 UTC by Tester
Modified: 2015-09-29 18:53 UTC (History)
4 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 for Bug 6602 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Tester 2012-08-19 13:29:52 UTC
WindowsBase.dll library's System.IO.Packaging.PackagePart.LoadRelationships(Dictionary<string, PackageRelationship> relationships, Stream stream) method appends "/" to the beginning of relationship's target uri. I'm not 100% certain this is a bug, but this appending breaks EPPlus (http://epplus.codeplex.com/) excel's xlsx file parser, that works perfectly on Microsoft's .Net. The failing code is this:				

PackagePart part; // excel sheet part
PackageRelationship sheetRelation = part.GetRelationship(...);
Uri uriWorksheet = PackUriHelper.ResolvePartUri(workbookUri, sheetRelation.TargetUri);

In the above case workbookUri is "/xl/workbook.xml" and sheetRelation.TargetUri is "/worksheets/sheet1.xml", and ResolvePartUri method returns the wrong result: "/worksheets/sheet1.xml". But if "/" wouldn't have been appended, TargetUri would be "worksheets/sheet1.xml", and ResolvePartUri would return correct result: "/xl/worksheets/sheet1.xml".

Since http://msdn.microsoft.com/en-us/library/system.io.packaging.packagerelationship.targeturi.aspx mentions that TargetUri is a relative uri, I think appending "/" is a bug.
Comment 1 Pablo Ruiz García 2012-10-14 04:14:14 UTC
I just sent a pull-request fixing this issue: https://github.com/mono/mono/pull/478

Hope it helps.
Comment 2 Eric Lawrence 2012-10-19 11:29:27 UTC
I have the following code:

using (Package oZip = Package.Open(sFilename, FileMode.Create)
  string sBaseURI = @"./raw/";
  Uri uriFirst = PackUriHelper.CreatePartUri(new Uri(sBaseURI + "file1.txt", UriKind.Relative));
  PackagePart oPart = oZip.CreatePart(uriFirst, "text/plain", CompressionOption.Normal);
  using (Stream strmWirteTo = oPart.GetStream()){
    // Write the file

On Windows, this works fine, and the ZIP archive has a subfolder named "Raw".

On Mac, this code runs, but the resultant ZIP file does not show a Raw subfolder either on Mac or Windows. That's because the PackUri helper ends up converting the URI into /./raw/ which is an illegal folder name.

Does your patch fix this too?

Comment 3 Maury Markowitz 2015-09-29 18:53:36 UTC
Having the same problem here, although it took me a while to figure out what was going on (the debugger was breaking on the wrong line for some reason).

This causes problems when you feed the Uris into PackUriHelper.ResolvePartUri, which then raises.

I solved it for now with:

    Uri PartUri;
    if (PackRel.TargetUri.IsAbsoluteUri) {
        PartUri = PackUriHelper.ResolvePartUri(PackRel.SourceUri, new Uri(PackRel.TargetUri.AbsolutePath, UriKind.Relative));
    } else {
        PartUri = PackUriHelper.ResolvePartUri(PackRel.SourceUri, PackRel.TargetUri);