【问题标题】:Mono c# TextView Buffer Deserialize Keeps CrashingMono c#TextView缓冲区反序列化不断崩溃
【发布时间】:2015-04-07 18:39:21
【问题描述】:

我不明白为什么这会一直崩溃!我将它插入到一个方法中,该方法显示 FileChooser 允许用户选择一个文件,然后如果选择了文件,则运行这段代码。我已经注释掉了运行程序的行并系统地跟踪它到 buffer.Deserialize 行。在添加此行之前,它将运行并且不会崩溃。粗略的 TextView Buffer Text 并不是每个都得到更新。

此外,在您评论之前,打开的文件是有效的保存文件,并且序列化和保存文件的方法完美无缺。只是打开的问题会崩溃。

byte[] data = System.IO.File.ReadAllBytes(fileChooser.Filename);

TextBuffer buffer = new TextView().Buffer;
Gdk.Atom serialFormat = buffer.RegisterDeserializeTagset(null); 
ulong length = (ulong) data.LongLength; 
TextIter iterator = buffer.StartIter; 
buffer.Deserialize ( buffer, serialFormat, ref iterator, data, length );

对于那些想成为聪明人并说这是已保存文件的人来说,这是我试图打开的已保存文件,它会导致它崩溃。好吧,任何文件都会崩溃,但这是我的测试文件。

GTKTEXTBUFFERCONTENTS-0001   Î <text_view_markup>
 <tags>
  <tag id="0" priority="0">
   <attr name="weight" type="gint" value="700" />
  </tag>
 </tags>
<text><apply_tag id="0">
Bold
</apply_tag>Hello World!</text>
</text_view_markup>

更新:我做了更多的修改,试图从程序中获取一些调试信息,因为它的运行方式只是崩溃并且在崩溃时没有提供任何价值。我现在从调试器中得到这个。

GLib.GException: Line 8 character 1: Anonymous tag found and tags can not be created. at Gtk.TextBuffer.Deserialize(TextBuffer content_buffer, Atom format, TextIter& iter, Byte[] data, UInt64 length)

【问题讨论】:

  • 那个文件绝对不是二进制序列化文件。你是如何创造它的?编辑:似乎是一种自定义方法。你是如何创建它的?
  • 什么是崩溃/异常/错误信息?
  • 它是使用 byte[] data = mainEditor.Buffer.Serialize(mainEditor.Buffer, format, iterator1, iterator2); 创建的System.IO.File.WriteAllBytes(fileChooser.Filename, data);

标签: c# mono gtk#


【解决方案1】:

我能够阻止崩溃,但现在在尝试使其正常运行时遇到了其他问题。原来的问题不再是问题。

通过改变解决原来的

到这个代码

private string mimeType = "text/plain";
...
buffer.Deserialize ( 
                    mainEditor.Buffer, 
                    mainEditor.Buffer.RegisterDeserializeTagset(mimeType), 
                    ref iterator, 
                    data, 
                    (ulong)data.LongLength
                );

它需要一个适当的 mimeType 否则它会崩溃,即使文档说它会将 null 作为有效选项除外!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-18
    • 1970-01-01
    相关资源
    最近更新 更多