我们目前有一个应用程序(Windows服务),它连接到另一个我们的应用程序并获取发票。在发票中,有一个RTF字段用于页眉/页脚字段。当我们获取数据时,使用以下代码将RTF转换为纯文本:
public static string ConvertFromRTFToPlainText(string rtfString)
{
if (rtfString == null)
return null;
System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox();
if (rtfString.StartsWith("{\\rtf1"))
rtBox.Rtf = rtfString;
else
rtBox.Text = rtfString;
return rtBox.Text;
}
这在大部分情况下都有效,但有些情况下(尤其是一个特定的客户端每次都会发生)我会遇到这个异常:
Exception Message:Error creating window handle.
Stack trace:
at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.TextBoxBase.CreateHandle()
at System.Windows.Forms.RichTextBox.set_Rtf(String value)
at SmartTrade.Common.API.Tools.RTFHelperUtility.ConvertFromRTFToPlainText(String rtfString)
at SmartTrade.Desktop.Proxy.API.ObjectMapper.InvoiceObjectMapper.CovertToAPIInvoice(Invoice domainInvoice)
任何有关这种情况发生原因或我们如何解决它的帮助都将不胜感激。编辑:感谢Jeremy的解释,我正在寻求RTF转换替代方案的建议。
System.Windows.Forms
的控件)。它甚至可能在某个壁橱里运行在一个没有显示器的盒子上。 - Thomas