Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Malformed mailto Hyperlink causes Exception on .NET 4.5+

See original GitHub issue


This issue is similar to #7 but for recent versions of the .NET framework.

If you create a blank document and set some text to the following field code (note the extra space): { HYPERLINK "" }

Running the following on .NET 4.0 will work fine: var wpdoc = WordprocessingDocument.Open(@"TestDoc.docx", false) Running the same line on .NET 4.5+ will throw the following exception:

DocumentFormat.OpenXml.Packaging.OpenXmlPackageException: Invalid Hyperlink: Malformed URI is embedded as a hyperlink in the document.
   at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Load() in OpenXmlPackage.cs: line 490
   at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.OpenCore(String path, Boolean readWriteMode) in OpenXmlPackage.cs: line 402
   at DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Open(String path, Boolean isEditable, OpenSettings openSettings) in PackageDocument.cs: line 297
   at  DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Open(String path, Boolean isEditable) in PackageDocument.cs: line 256

The inner-exception being this:

   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
   at System.Uri..ctor(String uriString, UriKind uriKind)
   at MS.Internal.IO.Packaging.InternalRelationshipCollection.ProcessRelationshipAttributes(XmlCompatibilityReader reader)
   at MS.Internal.IO.Packaging.InternalRelationshipCollection.ParseRelationshipPart(PackagePart part)
   at MS.Internal.IO.Packaging.InternalRelationshipCollection..ctor(Package package, PackagePart part)
   at System.IO.Packaging.PackagePart.EnsureRelationships()
   at System.IO.Packaging.PackagePart.GetRelationshipsHelper(String filterString)
   at System.IO.Packaging.PackagePart.GetRelationships()
   at DocumentFormat.OpenXml.Packaging.PackagePartRelationshipPropertyCollection..ctor(PackagePart packagePart)
   at DocumentFormat.OpenXml.Packaging.OpenXmlPart.Load(OpenXmlPackage openXmlPackage, OpenXmlPart parent, Uri uriTarget, String id, Dictionary`2 loadedParts)
   at DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.LoadReferencedPartsAndRelationships(OpenXmlPackage openXmlPackage, OpenXmlPart sourcePart, RelationshipCollection relationshipCollection, Dictionary`2 loadedParts)
   at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.Load()

I assume this is due to the following change introduced in .Net 4.5 ( An invalid mailto: URL throws an exception in the Uri class constructor.

Word seems to be perfectly happy with the malformed mailto hyperlink so I assume this would count as a valid document. I am therefore not sure how this could be fixed elegantly.


Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:24 (14 by maintainers)

github_iconTop GitHub Comments

abelykh0commented, Sep 30, 2020

@igitur Thank you. But sorry, I do not think it is a good idea. On the one hand, this code adds a traversal, which will reduce performance. On the other hand, this code seems to modify the original document.

igiturcommented, Sep 30, 2020

@vogla This was fixed in . Even if it weren’t, the cool thing with open source software is that you can fix it yourself. And if you’re really nice, you can contribute it back to the original project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Malformed mailto Hyperlink causes Exception on .NET 4.5+
An invalid mailto: URL throws an exception in the Uri class constructor. Word seems to be perfectly happy with the malformed mailto hyperlink...
Read more >
MalformedLineException Class (Microsoft.VisualBasic.FileIO)
Initializes a new instance of the MalformedLineException class with a specified error message and a reference to the inner exception that is the...
Read more >
FileFormatException Class (System.IO)
Definition. The exception that is thrown when an input file or a data stream that is supposed to conform to a certain file...
Read more >
c# - HttpClient send XML PostAsync Malformed request
I am trying to send a xml to a server and it always throw an exception Malformed request: Premature end of file.
Read more >
eM Clien trying to verify database
Today, I want to know what is causing this. ... SQLiteException (0x80004005): database disk image is malformed malformed database ... NET to versio...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found