Fix OmniSharp error 'No default runtime found' in Visual Studio Code on Windows

I wanted to mess around with [.NET Core](https://dotnet.github.io/getting-started/#/windows" target="_blank) on my machine and create a simple application. I'm not talking about [ASP.NET Core 1.0](https://get.asp.net/" target="_blank) but .NET Core 1.0. And yes, they are different! Very different. The .NET Core applications rely on the dotnet toolchain whereas ASP.NET Core ones rely on the dnx, dnvm, dnu toolchain. Can it get any more confusing? Of course it can, just wait until you have to start targeting frameworks in your libraries. It's awesome(ly) confusing and I hope things are streamlined before we hit RTM. But until then, I want to work/play with it.

Going back to the issue at hand, both ASP.NET Core 1.0 and .NET Core 1.0 rely on a runtime which, in this case, is what the CoreCLR 1.0 is all about. An open source, cross-platform runtime for .NET application.

To get started, I installed .NET Core 1.0 from the official [website](https://dotnet.github.io/getting-started/#/windows" target="_blank) using the provided .msi. And then I created a project using the instructions in step 2:

c:\Users\chmatsk> mkdir testapp
c:\Users\chmatsk> cd testapp
c:\Users\chmatsk\testapp> dotnet new

So far so good! Let's run it:

c:\Users\chmatsk\testapp> dotnet restore
c:\Users\chmatsk\testapp> dotnet run

And it's a success! We have a lift off, albeit a small one that doesn't do much…You can use any editor/IDE to write code and I tend to prefer [Visual Studio Code](https://code.visualstudio.com/Download" target="_blank) because it's lightweight and fast! If you haven't tried it before, I would urge you to download it and have a play. It's cross-platform and OSS, so win-win.

I opened my application folder in VS Code and straight away I could see that there was something missing: IntelliSense. Now, IntelliSense is a funny thing. As a Filip Woz recently said in his talk at ConFoo, Intellisense is like drugs. You're perfectly happy doing your work when you've never had it, but once you try it once, you'll never wanna go back! This means, that I needed intelligence as well and I needed it badly.

The VS Code team and the Open Source community has our backs. [OmniSharp](http://www.omnisharp.net/" target="_blank) is an awesome open source project that allows various IDEs to use a language service for IntelliSense and then some more (code correction, refactoring, suggestions etc). It's a full-blown language service that works beautifully cross-platform and offers a consistent experience when writing C# code. In Visual Studio code, you can install the C# language extension, which, in turn, will install OmniSharp. With the extension installed I was all fired up and ready to start coding. Instead, what I got was this ugly error from OmniSharp.

[INFO] Starting OmniSharp at 'c:\Users\chmatsk\testapp'...
[INFO] Started OmniSharp from 'C:\Users\chmatsk\.vscode\extensions\ms-vscode.csharp-0.3.7\bin\omnisharp.cmd' with process id 14288...
[INFORMATION:OmniSharp.Startup] Omnisharp server running using stdio at location 'c:\Users\chmatsk\testapp' on host 3952.
[ERROR:OmniSharp.Dnx.DnxPaths] The specified runtime path 'default' does not exist. Searched locations C:\Users\chmatsk\.dnx\runtimes\dnx-clr-win-x86.default
C:\Users\chmatsk\.dnx\runtimes\kre-clr-win-x86.default
C:\Users\chmatsk\.dnx\packages\KRE-CLR-x86.default
C:\Users\chmatsk\.k\runtimes\dnx-clr-win-x86.default
C:\Users\chmatsk\.k\runtimes\kre-clr-win-x86.default
C:\Users\chmatsk\.k\packages\KRE-CLR-x86.default
C:\Users\chmatsk\.kre\runtimes\dnx-clr-win-x86.default
C:\Users\chmatsk\.kre\runtimes\kre-clr-win-x86.default
C:\Users\chmatsk\.kre\packages\KRE-CLR-x86.default.
Visit https://github.com/aspnet/Home for an installation guide.
[INFORMATION:OmniSharp.Dnx.DnxProjectSystem] Scanning 'c:\Users\chmatsk\testapp' for DNX projects
[INFORMATION:OmniSharp.Dnx.DnxProjectSystem] Found project 'c:\Users\chmatsk\testapp\project.json'.
[INFORMATION:OmniSharp.Dnx.DnxProjectSystem] No default runtime found
The specified runtime path 'default' does not exist. Searched locations C:\Users\chmatsk\.dnx\runtimes\dnx-clr-win-x86.default
C:\Users\chmatsk\.dnx\runtimes\kre-clr-win-x86.default
C:\Users\chmatsk\.dnx\packages\KRE-CLR-x86.default
C:\Users\chmatsk\.k\runtimes\dnx-clr-win-x86.default
C:\Users\chmatsk\.k\runtimes\kre-clr-win-x86.default
C:\Users\chmatsk\.k\packages\KRE-CLR-x86.default
C:\Users\chmatsk\.kre\runtimes\dnx-clr-win-x86.default
C:\Users\chmatsk\.kre\runtimes\kre-clr-win-x86.default
C:\Users\chmatsk\.kre\packages\KRE-CLR-x86.default.
Visit https://github.com/aspnet/Home for an installation guide.

[INFORMATION:OmniSharp.MSBuild.MSBuildProjectSystem] No solution files found in 'c:\Users\chmatsk\testapp'
[INFORMATION:OmniSharp.ScriptCs.ScriptCsProjectSystem] Detecting CSX files in 'c:\Users\chmatsk\testapp'.
[INFORMATION:OmniSharp.ScriptCs.ScriptCsProjectSystem] Could not find any CSX files
[INFORMATION:OmniSharp.Startup] Solution has finished loading

The problem is that OmniSharp is trying to find the CoreCRL but fails because that path doesn't exist. It's safe to ignore the .k and .kre paths as these are legacy. I'm sure I installed the runtime as part of the Visual Studio 2015 Update 2 installation and update to the web tools but, obviously, this wasn't enough. So I decided to go back to the command-line to ensure that things have been properly installed. First, I checked for the runtime using the dnvm list command:

c:\Users\chmatsk\testapp>dnvm list

This returned nothing! OK…We may as well install it

c:\Users\chmatsk\testapp>dnvm install latest

Rerunning the dnvm list returned a result:

Active Version           Runtime Architecture OperatingSystem Alias
------ -------           ------- ------------ --------------- -----
  *    1.0.0-rc1-update2 clr     x86          win

The solution

We have a runtime has been installed and there's a .dnx folder in the location that OmniSharp expects it. Inside the .dnx folder, there's packages and runtimes folders which is what you should see if DNX is installed properly. But this wasn't enough. I restarted VS Code but OmniSharp threw the same error again.

I went back to the dissect the error message. I looked more carefully and I noticed that every searched location had a .default suffix. I decided to spend some time inside the OmniSharp extension (mine was in C:\Users\chmatsk.vscode\extensions\ms-vscode.csharp-0.3.7) hoping to find a configuration setting that mapped 'default' to something. But I didn’t have any luck and I assumed that having to mess with OmniSharp's configuration files was not the right solution anyway. Google/Bing to the rescue. That's when I stumbled upon an old thread in OmniSharp's GitHub repo:

https://github.com/Microsoft/vscode/issues/126

In one of the answers, I realized that what OmniSharp was looking for was the 'default' alias against a/the CoreCLR runtime. That makes sense. The fix was to run the following command to assign an alias to the preferred runtime (the one with the asterisk *):

c:\Program Files\dotnet\bin>dnvm alias default 1.0.0-rc1-update2
Setting alias 'default' to 'dnx-clr-win-x86.1.0.0-rc1-update2'

After that, the dnvm list command produced the following output:

Active Version           Runtime Architecture OperatingSystem Alias
------ -------           ------- ------------ --------------- -----
  *    1.0.0-rc1-update2 clr     x64          win
       1.0.0-rc1-update2 clr     x86          win             default

Opening my .NET Core project in VS Code now produced a much healthier log in the OmniSharp tab. I've attached a sample below for your reference:

[INFO] Starting OmniSharp at 'c:\Users\chmatsk\testapp'...
[INFO] Started OmniSharp from 'C:\Users\chmatsk\.vscode\extensions\ms-vscode.csharp-0.3.7\bin\omnisharp.cmd' with process id 3416...
[INFORMATION:OmniSharp.Startup] Omnisharp server running using stdio at location 'c:\Users\chmatsk\testapp' on host 16932.
[INFORMATION:OmniSharp.Dnx.DnxPaths] Using runtime 'C:\Users\chmatsk\.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc1-update2'.
[INFORMATION:OmniSharp.Dnx.DnxProjectSystem] Scanning 'c:\Users\chmatsk\testapp' for DNX projects
[INFORMATION:OmniSharp.Dnx.DnxProjectSystem] Found project 'c:\Users\chmatsk\testapp\project.json'.
[INFORMATION:OmniSharp.Dnx.DesignTimeHostManager] Process ID 12416
[INFORMATION:OmniSharp.Dnx.DesignTimeHostManager] Listening on port 2147
[INFORMATION:OmniSharp.Dnx.DesignTimeHostManager] Running DesignTimeHost on port 2147, with PID 12416
[INFORMATION:OmniSharp.Dnx.DnxProjectSystem] Connected
[INFORMATION:OmniSharp.Dnx.DesignTimeHostManager] Client accepted 127.0.0.1:2147
[INFORMATION:OmniSharp.Dnx.DesignTimeHostManager] Client accepted 127.0.0.1:2147
[INFORMATION:OmniSharp.MSBuild.MSBuildProjectSystem] No solution files found in 'c:\Users\chmatsk\testapp'
[INFORMATION:OmniSharp.ScriptCs.ScriptCsProjectSystem] Detecting CSX files in 'c:\Users\chmatsk\testapp'.
[INFORMATION:OmniSharp.ScriptCs.ScriptCsProjectSystem] Could not find any CSX files
[INFORMATION:OmniSharp.Startup] Solution has finished loading

Problem solved! I hope this helps in case you end up here facing the same error message and wondering what went wrong…