Debugging scripts

You are on a machine via Remote Desktop, there is no Visual Studio in sight, nor you can install, nor you want to install anything, and script does not work. What's next?

Enable script debug output (you'll need DebugView for Windows to see the output)
 

If //debug is specified, if script fails with exception, a complete error message is produced. For example, there is a script:
You are on a machine via Remote Desktop, there is no Visual Studio in sight, nor you can install, nor you want to install anything, and script does not work. What's next?

Enable script debug output (you'll need DebugView for Windows to see the output)
 

If //debug is specified, if script fails with exception, a complete error message is produced. For example, there is a script:
 

which when executed attempts to divide by 0:
 

To enable debug output and print it to console there is //debugc switch (debugc= debug to console)
 

Same, but enable debug output and print it to console, including script engine details, is done via //verbose:
 

Same, as above, but also trace lines of code as they execute
 

Measure script execution time, display exit code and ask for a key press before exit
 

Using ToDump

Using the previous steps you may determine where the program throws an exception, how execution goes, how to print debug messages etc.

It is as important to see variables defined at critical script points. Of couse, can use the usual ToString method, but it often produces rather useless results for complex objects.

XSharper has a few special methods for converting objects variables:

Shortcut name Full method name Description
.ToDump Dump.ToDump Convert a .NET object graph to string
.ToDumpAll ScriptContext.ToDumpAll Convert all defined XSharper variables to string (a filter may be specified to dump only some variables
.Dump ContextWriter.Dump Shortcut for ContextWriter.WriteDump.ToDump(object))
.Dump ScriptContext.Dump Shortcut for Out.Write(Dump.ToDump(object))

What it all means is easier to demonstrate:
 

prints