3

I'm trying to set the Syntax Highlighting in my program I'm making that uses AvalonEdit

This is the code that I'm using:

StreamResourceInfo sri = Application.GetResourceStream(new Uri("lua.xshd"));
        using (Stream s  = sri.Stream)
        {
            using (XmlTextReader reader = new XmlTextReader(s))
            {
                var gLua = HighlightingLoader.LoadXshd(reader);
                editor.SyntaxHighlighting = HighlightingLoader.Load(gLua, HighlightingManager.Instance);
                editor.Text = reader.ToString();
            }
        }

I'm also getting

A first chance exception of type 'System.UriFormatException' occurred in System.dll

How should I change this to make it work?

H.B.
  • 166,899
  • 29
  • 327
  • 400
Zach
  • 37
  • 2
  • 9

2 Answers2

1

I use

using (Stream s = File.OpenRead(@"C:\Users\JFM\Documents\latex3.xshd")) 
{
using (XmlTextReader reader = new XmlTextReader(s)) 
 {
   editor.SyntaxHighlighting = ICSharpCode.AvalonEdit.Highlighting.Xshd.HighlightingLoader.Load
       (reader, ICSharpCode.AvalonEdit.Highlighting.HighlightingManager.Instance);    
 }
}
J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
0

It is because you didn't include your assembly name. So it should be something like this if you build your xshd as embedded resource.

    private void LoadHightLightRule()
    {
        using (Stream s = myAssembly.GetManifestResourceStream("Your_Assembly_Name.lua.xshd"))
        {
            using (XmlTextReader reader = new XmlTextReader(s))
            {
                Editor.SyntaxHighlighting = HighlightingLoader.Load(reader, HighlightingManager.Instance);
            }
        }
    }
Kuree
  • 118
  • 7