Calling current project methods from C# Interactive Window in Visual Studio 2015 ?

By | March 2, 2016

The C# Interactive Window in Visual Studio is a great utility to play around the code, language features, API’s and other .NET framework features. The Interactive Window also support features like IntelliSense, syntax highlighting and navigating through executed commands. It is a REPL  (Read–eval–print loop) that provides us an environment for live coding and evaluate expression or code snippet based on our inputs. 

Few months back I published several post on Use C# Interactive Window for your coding experiment in Visual Studio 2015  and also Executing C# Scripts from Command Line or C# Interactive Windows in Visual Studio. We also talked about Command Line C# Interactive Script Execution for Visual Studio .

Recently I received a query on – are there any ways I can call current project methods in interactive window   ?  Well, of course we can do it.

We can Add a metadata reference to specified assembly and all its dependencies, including an executable in Interactive Window.

Let’s take a look with an example. Consider you have an Executable with Method Add() and a Class Library that has method GetResult();


Now if you want to call any of these current project methods, first open the C# Interactive Window:

To launch the Interactive window navigate through  Views > Other Windows > C# Interactive

Then use #r to load the DLL or Executable in to it. for an example, #r “<dll path>”


Once you execute this command, you should be able to access all the public methods from the DLL.

Step 1 :


Step 2 :


Similarly for an executable (exe) you can load it using similar way.


The cool part of this REPL is not only you have intellisense with your code, while accessing any folders during selection of files, it detects the paths automatically.


Keep in mind, Interactive Window calls the build code and it does not run in debug mode. So you can’t put breakpoint and debug you code while calling them from interactive window.

Hope this help and you will start exploring this more !

Thanks !