- open the attached msg file inside an aspose MailMessage object
- save the contents to a MemoryStream in mhtml format
- use the MemoryStream to construct an aspose Words.Document
- save the Words.Document as an xps file
- open the xps file inside a .NET XpsDocument object
- call xpsDoc.GetFixedDocumentSequence and it will raises two successive exceptions
System.UriFormatException occurred Message=Invalid URI: The hostname could not be parsed. Source=System StackTrace: at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind) InnerException:
System.Windows.Markup.XamlParseException occurred Message=Cannot convert string 'http://www.kutana.co.uk%3chttp:/www.kutana.co.uk/' in attribute 'NavigateUri' to object of type 'System.Uri'. Invalid URI: The hostname could not be parsed. Error at object 'System.Windows.Documents.Glyphs', Line 46 Position 885. Source=PresentationFramework LineNumber=46 LinePosition=885 NameContext=Page1 StackTrace: at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType) InnerException: System.UriFormatException Message=Invalid URI: The hostname could not be parsed. Source=System StackTrace: at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind) at System.UriTypeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) at System.Windows.Markup.XamlTypeMapper.ParseProperty(Object targetObject, Type propType, String propName, Object dpOrPiOrFi, ITypeDescriptorContext typeContext, ParserContext parserContext, String value, Int16 converterTypeId) InnerException:The exception occurs because the NavigateUri attribute in the generated xps file is malformed:
<Glyphs OriginX="26.468999863" OriginY="10.473999977"
UnicodeString="www.kutana.co.uk<http://www.kutana.co.uk/"
Indices="449,71.484375;449,71.484375;449,71.484375;856,25.244140625;364,45.458984375;437,52.5390625;410,33.49609375;258,47.900390625;374,52.5390625;258,47.900390625;856,25.244140625;272,42.28515625;381,52.734375;856,25.244140625;437,52.5390625;364,45.458984375;1092,49.8046875;346,52.5390625;410,33.49609375;410,33.49609375;393,52.5390625;855,26.7578125;876,38.623046875;876,38.623046875;449,71.484375;449,71.484375;449,71.484375;856,25.244140625;364,45.458984375;437,52.5390625;410,33.49609375;258,47.900390625;374,52.5390625;258,47.900390625;856,25.244140625;272,42.28515625;381,52.734375;856,25.244140625;437,52.5390625;364,45.458984375;876,38.623046875"
Fill="#FF0563C1"
FontRenderingEmSize="11"
FontUri="/Resources/99c2763d-ae70-4a4a-8857-910e33c80ed8.odttf"
FixedPage.NavigateUri="http://www.kutana.co.uk%3chttp:/www.kutana.co.uk/" />
This exception halts my app. There are a couple of places where I could deal with the problem:
- I know that this particular initial msg has malformed content. Could I fix the contents of the MailMessage object?
- The generated mhtml and xps content each have a malformed Uri. Can I set options so the generated Mhtml or xps has a legitimate NavigateUri value instead?
- Is there an option to the XpsDocument so it doesn't try to parse the NavigateUri attribute?
I don't need the Uri to be validated as I'm printing the xps content, not presenting it via a UI allowing a user to click and follow the link.