Bug 34414 - System.IO.Packaging problem with readonly files
Summary: System.IO.Packaging problem with readonly files
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: WindowsBase (show other bugs)
Version: 4.0.0
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-09-29 16:53 UTC by Maury Markowitz
Modified: 2015-09-29 16:56 UTC (History)
1 user (show)

Tags:
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 34414 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:
Status:
NEW

Description Maury Markowitz 2015-09-29 16:53:08 UTC
My code reads XLSX files using System.IO.Packaging: 

    FStream = new FileStream(ConStr, FileMode.Open, FileAccess.Read, FileShare.Read);
    using (Package xlPackage = Package.Open(FStream, FileMode.Open, FileAccess.Read)) {
	foreach (PackageRelationship PackRel in xlPackage.GetRelationshipsByType(cXl07WorkbookRelSchema)) {
            WBPart = xlPackage.GetPart(PackUriHelper.ResolvePartUri(PackRel.SourceUri, PackRel.TargetUri));
	    RD = new XmlTextReader(WBPart.GetStream());
	    while (RD.Read()) {
//look for names of the worksheets inside
            }
         }

         foreach (PackageRelationship PackRel in WBPart.GetRelationshipsByType(cXl07SharedStringsRelSchema)) {
            ...
         }

The purpose of the first loop is to find the WBPart and then read its tags looking for sheets. If we don't find the WBPart or there's no sheets, we fail out as the file is malformed. Then we loop again, this time looking in WBPart for various other things, in this case the sharedstrings.

This code runs fine on the PC under .Net 4.5.x/VS2015. On Xamarin/Mac it fails at the second instance of GetRelationshipsByType if the file is read-only. Changing the stream and Package.Open to ReadWrite fixed the problem. As this instruction should certainly be available for read-only files, I am filing this as a bug.

The confusing part here is that the first call to GetRelationshipsByType worked fine, it was only as part of WBPart that there was a problem. 

I have /Library/Frameworks/Mono.framework/Versions/4.0.4/lib/mono/gac/WindowsBase/4.0.0.0__31bf3856ad364e35/WindowsBase.dll

The stack trace is:

  at System.IO.Packaging.Package.CheckIsReadOnly () [0x0000c] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/mcs/class/WindowsBase/System.IO.Packaging/Package.cs:113 
  at System.IO.Packaging.PackagePart.CreateRelationship (System.Uri targetUri, TargetMode targetMode, System.String relationshipType, System.String id, Boolean loading) [0x00000] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/mcs/class/WindowsBase/System.IO.Packaging/PackagePart.cs:128 
  at System.IO.Packaging.PackagePart.LoadRelationships (System.Collections.Generic.Dictionary`2 relationships, System.IO.Stream stream) [0x0008f] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/mcs/class/WindowsBase/System.IO.Packaging/PackagePart.cs:168 
  at System.IO.Packaging.PackagePart.get_Relationships () [0x00048] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/mcs/class/WindowsBase/System.IO.Packaging/PackagePart.cs:50 
  at System.IO.Packaging.PackagePart.GetRelationshipsByType (System.String relationshipType) [0x0000c] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr4/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.4/mcs/class/WindowsBase/System.IO.Packaging/PackagePart.cs:200 
  at DtaProject.ReadProjectFromStream (System.IO.Stream pDBStream) [0x00218] in /PC/ClassLibrary1/ClassLibrary1/DBData.cs:1538