Bugzilla – Bug 14811
PackagePart relationship IDs generated by System.IO.Packaging are not valid XML ids
Last modified: 2014-04-04 12:13:13 EDT
I compiled the trunk version of EPPlus, a library for working with Excel (xlsx)
files (Office Open XML format) with Xamarin Studio 4.0.12 for Mac OS:
After patching some hard-coded backslashes and paths in Sample_Main.cs, the
sample console application could execute the first few tests. Excel could not
read the generated files, though. The identical compiled code emitted from
Xamarin Studio but run under a Windows virtual machine with .NET generated
I found that the problem was related to PackagePart ids. After unzipping the
first sample xlsx file, hand-editing workbook.xml and workbook.xml.rels to
replace IDs with ones similar to those generated by .NET, and zipping the xlsx
file again, Excel could read it without errors or warnings.
After studying the similar bug 1462
(https://bugzilla.xamarin.com/show_bug.cgi?id=1462) I have realized that the
issue is that PackagePart generates invalid XML ids. The ids do not need to
have the same structure as those generated by .NET, but they do need to start
with an XML NameStartChar. (Not that I have tested anything other than a few of
the letters a-z with Excel.)
The method NextId() used to be exactly duplicated in Package.cs and
PackagePart.cs, but in Package.cs, it has been patched (bug 1462) to prefix the
id with two letters (Re).
The same patch should be applied to NextId(), or the code should be refactored
to use a common ID generator.
I am unfortunately not familiar with the procedure to upload an actual patch to
the version control system, but my hope is that someone with more experience
might volunteer to do that.
Basically, line 240 of PackagePart.cs needs to be changed to match line 347 of
Package.cs. A search in GitHub for "relationshipId.ToString" yields no other
files that are in obvious need of being patched in a similar way.
The change was added a while ago and survived