Thanks to visit codestin.com
Credit goes to github.com

Skip to content

"Specified part does not exist in the package." exception thrown when calling DeletePart() #1968

@mlucero-isw

Description

@mlucero-isw

Exception type: InvalidOperationException

Exception message: "Specified part does not exist in the package."

Stack trace:

at System.IO.Packaging.Package.GetPart(Uri partUri)
at DocumentFormat.OpenXml.Features.PackageFeatureBase.DocumentFormat.OpenXml.Packaging.IPackage.GetPart(Uri uriTarget)
at DocumentFormat.OpenXml.Packaging.Builder.DelegatingPackageFeature.GetPart(Uri uriTarget)
at DocumentFormat.OpenXml.Packaging.Builder.DelegatingPackageFeature.GetPart(Uri uriTarget)
at DocumentFormat.OpenXml.Packaging.PackageUriHandlingExtensions.MalformedUriHandlingPackage.GetPart(Uri uriTarget)
at DocumentFormat.OpenXml.Packaging.OpenXmlPart.Load(OpenXmlPackage openXmlPackage, OpenXmlPart parent, Uri uriTarget, String id)
at DocumentFormat.OpenXml.Packaging.PartRelationshipsFeature.LoadReferencedPartsAndRelationships()
at DocumentFormat.OpenXml.Packaging.PartRelationshipsFeature.get_RelationshipMap()
at DocumentFormat.OpenXml.Packaging.PartRelationshipsFeature.DocumentFormat.OpenXml.Features.IPartRelationshipsFeature.get_Parts()
at DocumentFormat.OpenXml.Packaging.OpenXmlPart.FindAllReachableParts(IDictionary2 reachableParts) at DocumentFormat.OpenXml.Packaging.OpenXmlPart.FindAllReachableParts(IDictionary2 reachableParts)
at DocumentFormat.OpenXml.Packaging.OpenXmlPart.FindAllReachableParts(IDictionary2 reachableParts) at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.FindAllReachableParts(IDictionary2 reachableParts)
at DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.DeletePartCore(String id)
at DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.DeletePart(String id)
at Jet.Nimbus.OpenXmlUtility.AddPartToDocument(String partId, String rootElementName, SpreadsheetDocument document, String xml) in C:\repos\NimbusEngine\Jet.Nimbus\OpenXmlUtility.cs:line 212

Hello, currently seeing a somewhat strange issue and was hoping for some insight on what could be causing it.

In our code, we check to see if a CustomXml part with a certain name exists, and if it does then we go ahead and delete that part from our SpreadsheetDocument object's WorkbookPart property. But even though it exists, that exception gets thrown. If we catch, log, and ignore the exception, I can see that the part with that specific name doesn't exist anymore in WorkbookPart.ChildrenRelationshipParts. So it looks like it deletes it from there but that exception gets thrown, but unclear why.

Here is the really weird thing that I notice when debugging in Visual Studio is that if I hit a breakpoint right before the DeletePart() call and hover over my SpreadsheetDocument object and look into WorkbookPart.ChildrenRelationshipParts property and enumerate results in VS, then continue code execution, that exception above doesn't get thrown and it deletes the part just fine. I even tried to enumerate programmatically over the Parts property to see if that'll "pre-load" anything, but no avail.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions