DuoCode Uses Roslyn to Transpile C# into JavaScript

by Sergio De Simone on Feb 03, 2015 |

DuoCode is a C# to JavaScript compiler that promises to allow developers to build HTML5 applications using C# and the .NET framework inside of Visual Studio. InfoQ has interviewed its creators to learn more.

DuoCode claims to support a number of C# features, including strong-typing, class-based inheritance, reflections, generics, lambda expressions and Linq. Other advantages that DuoCode should provides are:

  • debugging the original C# code: DuoCode uses source mappings that should allow developers to see and step through the original C# code inside Visual Studio or the browser.

  • strongly-typed DOM and WebGL: this can be exemplified in the two examples below:

    using static DuoCode.Dom
    string userAgent = navigator.userAgent
    HTMLScriptElement script = (HTMLScriptElement)document.getElementById(scriptId);
    WebGLRenderingContext gl = canvas.getContext("webgl");
    gl.bindBuffer(GL.ARRAY_BUFFER, bCubeTextureCoords);
    gl.vertexAttribPointer(aTextureCoord, 2, GL.FLOAT, false, 0, 0);
    gl.bindTexture(GL.TEXTURE_2D, texture);
    gl.uniform1(uSampler, 0);
  • compilation speed: according to DuoCode, "most of the times, the compilation is even faster than the standard C# compilation of the same code."

  • support for Continuous Integration: DuoCode claims to be fully integrated with MSBuild and can be run as an MSBuild task, or as a command-line tool.

InfoQ has spoken to Stav Harel, manager of DuoCode launch.

Could you describe a few cases or scenarios where transpiling C# into JavaScript can be advantageous? What kind of customers do you have in mind?

Cross-compiling C# into JavaScript is very advantageous in allowing developers to use C# to develop JavaScript-HTML5 Web applications while enjoying the convenience of the C# language, Visual Studio, and debugging based on source-maps.

A few sample scenarios in which DuoCode can greatly benefit developers: Game development with WebGL; Server-side development with NodeJS; Building mobile applications with Cordova.

Moreover, it is the perfect solution for organizations that have already established their C# assets (projects and code, knowledge and experienced C# developers) to reuse their C# resources and efficiently develop JavaScript projects.

Could you provide some details about the way you use Roslyn and what benefits it brings?

DuoCode "understands" C# using the Roslyn compiler. Roslyn performs the code parsing, syntactic tree (AST) generation and contextual analysis. Then DuoCode takes over to perform the code translation and generates JavaScript code (along with source-maps) while completing language features that exist in C# and are missing in JavaScript.

Reliance on Roslyn has vital importance, as it allows DuoCode to keep up with latest technologies like C# 6.0 and Visual Studio 2015.

There are already a few transpilers from C# into JavaScript. What makes DuoCode unique in your view?

Several attempts to develop C#-to-JavaScript compilers have been introduced in the previous years, but they suffer from clear shortcomings.

Their support of C# is partial at best; their interoperability with existing JS libraries is insufficient; some of them produce a cumbersome code that is not readable (and looks like assembly code); some of them do not permit debugging in C#.

All existing solutions rely on old compilers and are maladapted to new features of Visual Studio 2015.

DuoCode is currently in closed beta. A request to join the program can be submitted from DuoCode web site.

Rate this Article


Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Sounds promising! I hope my beta invite arrives soon. by First name Last name

This actually sounds like a proper solution for bridging between JS and modern languages. Someone pinch me.

Re: Sounds promising! I hope my beta invite arrives soon. by Charles Humble

Thanks for your comment. Would you be nice enough to edit your profile and put in your real name? Although we haven’t published any restriction from using aliases, the intent for InfoQ discussions is to maintain a level of professionalism, in which using real names is an important factor. Thanks.

Charles Humble
Head of Editorial,

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

2 Discuss
General Feedback
Marketing and all content copyright © 2006-2016 C4Media Inc. hosted at Contegix, the best ISP we've ever worked with.
Privacy policy

We notice you're using an ad blocker

We understand why you use ad blockers. However to keep InfoQ free we need your support. InfoQ will not provide your data to third parties without individual opt-in consent. We only work with advertisers relevant to our readers. Please consider whitelisting us.