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

Skip to content

'Specified part does not exist' error message is not helpful #1971

@PeterAyad

Description

@PeterAyad

I am trying to open this file testFile.docx

using the code

 static void Main(string[] args)
 {
     try
     {
         using (WordprocessingDocument doc = WordprocessingDocument.Open("testFile.docx", false))
         {
             Console.WriteLine("File is opened!");
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("General Exception caught:");
         Console.WriteLine($"Type: {ex.GetType()}");
         Console.WriteLine($"Message: {ex.Message}");
         Console.WriteLine($"StackTrace: {ex.StackTrace}");
     }
 }

But I am getting this message which isn't helpful

General Exception caught:
Type: System.InvalidOperationException
Message: Specified part does not exist in the package.
StackTrace: at System.IO.Packaging.Package.GetPart(Uri partUri)
at DocumentFormat.OpenXml.Features.PackageFeatureBase.DocumentFormat.OpenXml.Packaging.IPackage.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.DocumentFormat.OpenXml.Features.IReferenceRelationshipsFeature.get_Relationships()
at DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.get_ExternalRelationships()
at Demo.Program.Main(String[] args) in ...

Is there a way to find which part is missing?

Metadata

Metadata

Assignees

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