# ADDING REFERENCES TO ALTERNET.EDITOR.WPF.TEXTEDITOR

**URL:** <https://forum.alternetsoft.com/t/adding-references-to-alternet-editor-wpf-texteditor/127>\
**Category:** AlterNET Studio Support\
**Tags:** wpf, editor\
**Created:** [February 26, 2019, 12:00am UTC](https://forum.alternetsoft.com/t/adding-references-to-alternet-editor-wpf-texteditor/127 "2019-02-26T00:00:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tony.Valenti](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/t/606060/32.png) [@Tony.Valenti](https://forum.alternetsoft.com/u/Tony.Valenti)\
**Post date:** [February 26, 2019, 12:00am UTC](https://forum.alternetsoft.com/t/adding-references-to-alternet-editor-wpf-texteditor/127/1 "2019-02-26T00:00:00Z")

</div>

How do I add references to the Text Editor so that custom types that I've defined in another assembly get autocompletion and such?  
Something like my Parameters and Results class below:  
  
public static class Automation {  
  
 public static void Main(Parameters P, Results R) {  
  
 R.Output = $@"{P.Name} is {P.Age} years old!";  
  
 }  
}

---

<div class="post-metadata">

**Author:** ![andrew.medvedev](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/andrew.medvedev/32/28_2.png) [@andrew.medvedev](https://forum.alternetsoft.com/u/andrew.medvedev)\
**Post date:** [February 26, 2019, 12:00am UTC](https://forum.alternetsoft.com/t/adding-references-to-alternet-editor-wpf-texteditor/127/2 "2019-02-26T00:00:00Z")

</div>

Hi Tony,   
You can register any assembly for code completion using RegisterAssembly method of RoslynRepository (accessible via CsParser) like this:  
   
var csParser = new Alternet.Syntax.Parsers.Roslyn.CsParser();  
 csParser.Repository.RegisterAssembly(@"..\..\..\CustomAssembly\bin\debug\CustomAssembly.dll");  
 // if already loaded in appdomain, can just use csParser.Repository.RegisterAssembly("CustomAssembly");  
   
I've uploaded full demo project here:  
[https://drive.google.com/file/d/1GohDX2hMbBVpFiIu5vxSJ2DeWf905mAH/view?usp=sharing](https://drive.google.com/file/d/1GohDX2hMbBVpFiIu5vxSJ2DeWf905mAH/view?usp=sharing)  
   
Hope this helps.  
Andrew

---

<div class="post-metadata">

**Author:** ![Tony.Valenti](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/t/606060/32.png) [@Tony.Valenti](https://forum.alternetsoft.com/u/Tony.Valenti)\
**Post date:** [February 26, 2019, 12:00am UTC](https://forum.alternetsoft.com/t/adding-references-to-alternet-editor-wpf-texteditor/127/3 "2019-02-26T00:00:00Z")

</div>

Hi Andrew,  
I've tested out what you sent and it works great, however, I don't want to rely on hard coded paths or magic strings. I've made the following changes to your project and it will show the problem I'm facing:  
  
1. In CodeCompletion, add a reference to CustomAssembly.  
2. Set AssemblyPath as follows:  
var AssemblyPath = typeof(CustomAssembly.Parameters).Assembly.Location;  
  
If I do that, it seems as if the parse no longer loads the assembly. What do I need to do to make that work?

---

<div class="post-metadata">

**Author:** ![andrew.medvedev](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/andrew.medvedev/32/28_2.png) [@andrew.medvedev](https://forum.alternetsoft.com/u/andrew.medvedev)\
**Post date:** [February 26, 2019, 12:00am UTC](https://forum.alternetsoft.com/t/adding-references-to-alternet-editor-wpf-texteditor/127/4 "2019-02-26T00:00:00Z")

</div>

Hi Tony,  
There seems to be a small issue with the order of initialization of roslyn engine.  
This code should work:  
public MainWindow()  
 {  
 InitializeComponent();  
 var csParser = new Alternet.Syntax.Parsers.Roslyn.CsParser();  
 syntaxEdit1.Lexer = csParser;  
 syntaxEdit1.Lines.LoadFile(@"..\..\file.cs");  
 var assemblyPath = typeof(CustomAssembly.Parameters).Assembly.Location; csParser.Repository.RegisterAssembly(assemblyPath);  
 }  
you can also make sure that it's initialized before calling RegisterAssembly method:  
 private void InitWorkspace(Alternet.Syntax.Parsers.Roslyn.RoslynParser parser)  
 {  
 var workspace = parser.Repository.Solution.Workspace;  
 }  
 public MainWindow()  
 {  
 InitializeComponent();  
 var csParser = new Alternet.Syntax.Parsers.Roslyn.CsParser();  
 InitWorkspace(csParser);  
 var assemblyPath = typeof(CustomAssembly.Parameters).Assembly.Location;  
 csParser.Repository.RegisterAssembly(assemblyPath);  
 syntaxEdit1.Lexer = csParser;  
 syntaxEdit1.Lines.LoadFile(@"..\..\file.cs");  
 }  
regards,  
Andrew

---

<div class="post-metadata">

**Author:** ![walter.goodwater](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/w/606060/32.png) [@walter.goodwater](https://forum.alternetsoft.com/u/walter.goodwater)\
**Post date:** [May 15, 2019, 12:00am UTC](https://forum.alternetsoft.com/t/adding-references-to-alternet-editor-wpf-texteditor/127/5 "2019-05-15T00:00:00Z")

</div>

When I add references via parser.Repository.RegisterAssembly() it works, but the editor still shows red lines under my related classes until I go to the editor and start typing. Once I start typing, the lines all go away. Is there some other step I'm missing to get the editor to refresh its references?

---

<div class="post-metadata">

**Author:** ![wknauf](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/w/606060/32.png) [@wknauf](https://forum.alternetsoft.com/u/wknauf)\
**Post date:** [May 15, 2019, 12:00am UTC](https://forum.alternetsoft.com/t/adding-references-to-alternet-editor-wpf-texteditor/127/6 "2019-05-15T00:00:00Z")

</div>

Hi,  
after adding the reference, call this method (based on the code snippet in the previous post - you probably have a "RoslynParser" variable in your code):  
csParser.ReparseText();  
You can call this method only if you already have code in the parser, otherwise an exception will occur.  
Best regards  
Wolfgang
