首页 > 解决方案 > BizTalk - 设置电子邮件 contentType 导致错误:XML 文档中存在错误 (1, 1)

问题描述

当我尝试在 BizTalk 业务流程中设置 Microsoft.XLANGs.BaseTypes.ContentType 时,我收到一个 XML 错误(无论我使用的是“text/plain”还是“text/xml”。我使用的是动态发送端口PassThru 管道。

msg_Email.BodyPart = new Ledger6002.Component.RawString("See attached email. Method 2"); 
msg_Email.AttachmentPart = msg_Ledger6002_File_XmlDoc;

// Set the filename as it should display on the attachment in the email 
// (drop the path, just the filename/extension)
attachmentName = System.IO.Path.GetFileName(
                       msg_Ledger6002_File_XmlDoc(FILE.ReceivedFileName));

msg_Email.AttachmentPart(MIME.FileName) =  attachmentName; 

msg_Email.BodyPart(Microsoft.XLANGs.BaseTypes.ContentType) = "text/plain";
msg_Email.AttachmentPart(Microsoft.XLANGs.BaseTypes.ContentType) = "text/plain";

导致此错误:

xlang/s engine event log entry: Uncaught exception (see the 'inner exception' below) has suspended an instance of service 'Ledger6002.Logic.Ledger6002_Process_File(9eb6993c-87d0-7bf0-b0bf-e1f684000af2)'.
The service instance will remain suspended until administratively resumed or terminated. 
If resumed the instance will continue from its last persisted state and may re-throw the same unexpected exception.
InstanceId: 216e4bac-0f22-4e06-9e61-2ef46051c991
Shape name: msg_Email
ShapeId: e7ce3f54-0558-4756-a7e4-e3800721178f
Exception thrown from: segment 1, progress 55
Inner exception: There is an error in XML document (1, 1).
        
Exception type: InvalidOperationException
Source: System.Xml
Target Site: System.Object Deserialize(System.Xml.XmlReader, System.String, System.Xml.Serialization.XmlDeserializationEvents)
The following is a stack trace that identifies the location where the exception occured

   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
   at System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader)
   at Microsoft.XLANGs.Core.Value.GetObject(Type t)
   at Microsoft.XLANGs.Core.Value._prepareForWrite(PreferredValueRepresentation pvr)
   at Microsoft.XLANGs.Core.ValueTable.PrepareForWrite(ValueToken& vt, PreferredValueRepresentation pvr)
   at Microsoft.XLANGs.Core.Part.PrepareForWrite(PreferredValueRepresentation pvr)
   at Microsoft.XLANGs.Core.Part.SetPartProperty(Type propType, Object val)
   at Microsoft.XLANGs.Core.Part.SetPropertyValue(Type propType, Object val)
   at Ledger6002.Logic.Ledger6002_Process_File.segment1(StopConditions stopOn)
   at Microsoft.XLANGs.Core.SegmentScheduler.RunASegment(Segment s, StopConditions stopCond, Exception& exp)
Additional error information:

        Data at the root level is invalid. Line 1, position 1.
        
Exception type: XmlException
Source: System.Xml
Target Site: Void Throw(System.Exception)
The following is a stack trace that identifies the location where the exception occured

   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
   at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.XmlTextReader.Read()
   at System.Xml.XmlReader.MoveToContent()
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderObject.Read2_anyType()
    

msg_email 是一个多部分消息,有两个部分:bodyPart 和 attachmentPart,都定义为 RawString 自定义类。

什么可能导致此错误?我需要使用 MIME/编码器的管道吗?

我现在在另一个客户处,尝试回答 2017 年的问题(但使用编排而不是管道):如何设置附件名称以在 Outlook 中正确显示

当我注释掉设置 contentType 的两行时,我收到一封电子邮件,但问题与上面 2017 年帖子中提到的问题相同。

标签: biztalk-2016

解决方案


你至少错过了两件事:

  • 使用 SMTP.MessagePartsAttachments 设置并将其设置为“2”
  • 使用 SMTP.EmailBodyTextCharset 并将其设置为“UTF-8”

推荐阅读