我使用的是System。Windows。表格。RichTextBox,并具有以下代码:
var testRichTextBox = new System.Windows.Forms.RichTextBox();
var testText = @"{rtf1ansideff0{fonttbl{f0 Courier New;}}{colortblred0green0blue0;}fs20{cf0 ud{u160}}line }";
testRichTextBox.Rtf = testText;
这个相同的代码在中完美工作。净4.7.2.
当尝试在中运行它时。Net 6,会产生以下异常:
System.InvalidOperationException: Cannot load the text.
at System.Windows.Forms.RichTextBox.StreamIn(Stream data, SF flags)
at System.Windows.Forms.RichTextBox.StreamIn(String str, SF flags)
at System.Windows.Forms.RichTextBox.set_Rtf(String value)
在中的WinForms中断更改中找不到任何有关它的文档。MSDN上的Net6,这可能是什么原因造成的?
编辑:
代码在同一台机器上执行,并且不断更改。通过Visual Studio 的网络版本
#if !NETCOREAPP
var testRichTextBox = new System.Windows.Forms.RichTextBox();
var testText = @"{rtf1ansideff0{fonttbl{f0 Courier New;}}{colortblred0green0blue0;}fs20{cf0 ud{u160}}line }";
testRichTextBox.Rtf = testText;
#endif
#if NETCOREAPP
var testRichTextBox = new System.Windows.Forms.RichTextBox();
var testText = @"{rtf1ansideff0{fonttbl{f0 Courier New;}}{colortblred0green0blue0;}fs20{cf0 ud{u160}}line }";
testRichTextBox.Rtf = testText;
#endif
我以前的经历就是这样。5和6之前的Net版本似乎在执行严格的RTF方面更加宽松。
我的RTF字符串格式有问题,缺少一个结束符},它在中起作用。Net 4.7.2,但会出现与中所述相同的错误。净6。我在RTF标准中做了一些研究才弄清楚。
也许值得验证RTF,尽管对我来说,这比我预期的要困难,因为似乎缺乏这样做的工具。