# NullReference Exception when evaluating variables

**URL:** <https://forum.alternetsoft.com/t/nullreference-exception-when-evaluating-variables/92>\
**Category:** AlterNET Studio Support\
**Tags:** scripter, editor\
**Created:** [December 20, 2019, 12:00am UTC](https://forum.alternetsoft.com/t/nullreference-exception-when-evaluating-variables/92 "2019-12-20T00:00:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![thorsten.hoppe](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/t/606060/32.png) [@thorsten.hoppe](https://forum.alternetsoft.com/u/thorsten.hoppe)\
**Post date:** [December 20, 2019, 12:00am UTC](https://forum.alternetsoft.com/t/nullreference-exception-when-evaluating-variables/92/1 "2019-12-20T00:00:00Z")

</div>

Hello,  
when debugging script code we get the following error message. The error can be reproduced by stepping through the code in quick succession (Step into F11) while evaluating the local variables.  
ucLocals.EvaluateVariables((await Debugger.GetVariablesInScopeAsync()).VariableNames);  
Is this a known problem and is there already a solution?  
Regards  
Thorsten  
The exception message is:  
Beschreibung: Der Prozess wurde aufgrund einer unbehandelten Ausnahme beendet.  
Ausnahmeinformationen: System.NullReferenceException  
 bei Alternet.Scripter.Debugger.UI.Wpf.EvaluationResultsTreeController+\<\>c\_\_DisplayClass13\_0+\<b\_\_1\>d.MoveNext()  
 bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()  
 bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)  
 bei Alternet.Scripter.Debugger.UI.Wpf.EvaluationResultsTreeController+d\_\_18.MoveNext()  
 bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()  
 bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)  
 bei Alternet.Scripter.Debugger.UI.Wpf.EvaluationResultsTreeController+d\_\_19.MoveNext()  
 bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()  
 bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)  
 bei Alternet.Scripter.Debugger.UI.Wpf.EvaluationResultsTreeController+d\_\_13.MoveNext()  
 bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()  
 bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)  
 bei Alternet.Scripter.Debugger.UI.Wpf.Locals+\<\>c\_\_DisplayClass12\_0+\<b\_\_0\>d.MoveNext()  
 bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()  
 bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)  
 bei Alternet.Scripter.Debugger.UI.Wpf.VariablesEvaluationControlBase+d\_\_14.MoveNext()  
 bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()  
 bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)  
 bei Alternet.Scripter.Debugger.UI.Wpf.Locals+d\_\_12.MoveNext()  
 bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()  
 bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)  
 bei System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)  
 bei System.Windows.Threading.DispatcherOperation.InvokeImpl()  
 bei MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(System.Object)  
 bei System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)

---

<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:** [December 20, 2019, 12:00am UTC](https://forum.alternetsoft.com/t/nullreference-exception-when-evaluating-variables/92/2 "2019-12-20T00:00:00Z")

</div>

Hello,  
We tried to reproduce this issue, but with no success so far.  
regards,  
Andrew

---

<div class="post-metadata">

**Author:** ![thorsten.hoppe](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/t/606060/32.png) [@thorsten.hoppe](https://forum.alternetsoft.com/u/thorsten.hoppe)\
**Post date:** [December 20, 2019, 12:00am UTC](https://forum.alternetsoft.com/t/nullreference-exception-when-evaluating-variables/92/3 "2019-12-20T00:00:00Z")

</div>

Hello,  
the issue can be reproduced with below code (from the hello world sample) and your Extensibility Studio Demo.  
Just set a breakpoint at line 32: doc.Childrens.Add(new Document(doc));  
and press F10 key very often and quickly.  
Here the sample code:  
using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.Threading.Tasks;  
using System.Windows;  
using System.Windows.Controls;  
using System.Windows.Data;  
using System.Windows.Documents;  
using System.Windows.Input;  
using System.Windows.Media;  
using System.Windows.Media.Imaging;  
using System.Windows.Navigation;  
using System.Windows.Shapes;  
using System.IO;  
  
namespace HelloWorld.Wpf  
{  
/// #  
/// Interaction logic for MainWindow.xaml  
///   
public partial class MainWindow : Window  
{  
public MainWindow()  
{  
var x = this;  
  
var doc = new Document(null);  
for (int i = 0; i \< 10; i++)  
{  
doc.Childrens.Add(new Document(doc));  
}  
InitializeComponent();  
}  
  
private void button1\_Click(object sender, System.Windows.RoutedEventArgs e)  
{  
Close();  
}  
}  
public class Document  
{  
public Document(Document parent)  
{  
Parent =parent;  
Childrens = new List();  
  
\_media =new List();  
for (int i = 0; i \< 10; i++)  
{  
\_media.Add(new Medium());  
}  
\_pages =new List();  
for (int i = 0; i \< 10; i++)  
{  
\_pages.Add(new Page(this));  
}  
}  
public Document Parent{ get;}  
public List Childrens { get; set; }  
  
private List \_pages;  
  
public List Pages  
{  
get { return \_pages; }  
set { \_pages = value; }  
}  
  
private List \_media;  
  
public List Media  
{  
get { return \_media; }  
set { \_media = value; }  
}  
}  
public class Page  
{  
public Page(Document document)  
{  
Document = document;  
\_media = new List();  
}  
  
  
public Document Document { get; }  
  
  
public Medium DefaultMedium { get; set; }  
  
  
private List \_media;  
  
public List Media  
{  
get { return \_media; }  
set { \_media = value; }  
}  
private bool \_rear;  
  
public bool Rear  
{  
get { return \_rear; }  
set { \_rear = value; }  
}  
}  
public class Fields  
{  
private string \_name;  
  
public string Name  
{  
get { return \_name; }  
set { \_name = value; }  
}  
  
private string \_value;  
  
public string Value  
{  
get { return \_value; }  
set { \_value = value; }  
}  
}  
public class Medium  
{  
public Medium()  
{  
Id = Guid.NewGuid().ToString();  
}  
public string Id { get; set; }  
  
private string \_name;  
  
public string Name  
{  
get { return \_name; }  
set { \_name = value; }  
}  
  
private Stream \_stream;  
  
public Stream Stream  
{  
get { return \_stream; }  
set { \_stream = value; }  
}  
}  
}

---

<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:** [December 24, 2019, 12:00am UTC](https://forum.alternetsoft.com/t/nullreference-exception-when-evaluating-variables/92/4 "2019-12-24T00:00:00Z")

</div>

Hello,  
I've sent you fix via e-mail.  
Could you please try it and let me know whether this problem was fixed?  
regards,  
Andrew
