Roslyn throws The language 'C#' is not supported

asked9 years ago
last updated9 years ago
viewed4.6k times
Up Vote30Down Vote

I have created a and did some processing and also used Roslyn to generate code.

I use the library in a WPF GUI application as a reference.

These are the NuGet packages:

Build shows no error, however when I use the following code:

private static void GetGenerator()
{
  workspace = new AdhocWorkspace();
  generator = SyntaxGenerator.GetGenerator(workspace, LanguageNames.CSharp);
}

I get an exception:

"The language 'C#' is not supported."

at: Microsoft.CodeAnalysis.Host.HostWorkspaceServices.GetLanguageServices(String languageName)
   at: Microsoft.CodeAnalysis.Host.Mef.MefWorkspaceServices.GetLanguageServices(String languageName)
   at: Microsoft.CodeAnalysis.Editing.SyntaxGenerator.GetGenerator(Workspace workspace, String language)

According to this and this, I have to copy the CodeAnalysis files locally and add the necessary references. They are there, yet the error occurs.

Is this still a bug that wasn't fixed in the last year?

What else should I do?