Open lindexi opened 1 year ago
Hello, I believe I just encountered this issue. Is there a workaround based on the linked PR?
The error message is:
DocumentFormat.OpenXml.Packaging.OpenXmlPackageException: The document cannot be opened because there is an invalid part with an unexpected content type.
[Part Uri=/docMetadata/LabelInfo.xml],
[Content Type=application/xml],
[Expected Content Type=application/vnd.ms-office.classificationlabels+xml].
DocumentFormat.OpenXml.Packaging.OpenXmlPackageException:“The document cannot be opened because there is an invalid part with an unexpected content type. [Part Uri=/xl/styles.xml], [Content Type=application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml], [Expected Content Type=application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml].”
@JaneConan Sorry, I don't think we have the same problem.
Describe the bug
The
PresentationDocument.Open
will throw the OpenXmlPackageException exception when we open the document which Content_Types records paths with wrong case.The
[Content_Types].xml
records the PartName with wrong case, such as/ppt/presprops.xml
what we expect is/ppt/presProps.xml
.And we can open the document with Office PowerPoint, but fail with OpenXMLSDK.
Screenshots
To Reproduce // Please add a self-contained, minimum viable repro of the issue. // If you require external resources, please provide a gist or GitHub repro // An Xunit style test is preferred, but a console application would work too.
Steps to reproduce the behavior:
Observed behavior Throw the exception
Expected behavior The Open XML SDK can open the document file.
Desktop (please complete the following information):
Additional context
Why the Open XML SDK can not open this document? Because the Open XML SDK will use ZipPackage to get the ContentType, see
https://github.com/dotnet/runtime/blob/2d5a9162f6bd9583981d54363d077a04e4efc868/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ZipPackage.cs#L604-L624
But the
_overrideDictionary
does not ignore case, seehttps://github.com/dotnet/runtime/blob/2d5a9162f6bd9583981d54363d077a04e4efc868/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ZipPackage.cs#L694-L699
And it may be fixed in https://github.com/dotnet/Open-XML-SDK/pull/1295