C# In The Browser
Written by Ian Elliot   
Friday, 07 September 2012

Yes, you can write C# and get it to run in any browser which is something of a surprise. Miguel de Icaza has some good ideas about how this magic can be achieved.

This isn't exactly news, but it deserves to be better known.

A recent blog post by Mono's Miguel de Icaza discusses the idea of running C# programs in the browser - any browser. At a time when Microsoft doesn't seem as keen on all things .NET, Mono seems to be leading the way in extending its reach. This is a good idea for Mono because the more C# can be used the more it is likely that the Mono software will survive and flourish.

 

csharpbrowsers

Until recently one of the areas that C# has been absent from is the client-side browser. It is used on the server side in ASP.NET and it appears to be used directly in web pages as part of the ASP.NET MVC approach. However, in each case the code is run on the server and the results shipped to the browser as HTML.

As has been noted before (see Related Reading), JavaScript is becoming the intermediate language or high level assembler of the web. As Miguel's post points out the solution to C# on the browser is to compile it to JavaScript.

There are two .NET JavaScript compilers worth knowing about, JSIL and Saltarelle. The first, JSIL, is a bit more than a C# compiler because it translates IL (Intermediate Language) to JavaScript which means it can allow you to run any .NET language in the browser. To use it you have to first compile the program to IL and then IL to JavaScript. Saltarelle is more direct in that it uses the Mono C# Compiler as a Service to compile C# to JavaScript. It is missing some features at the moment but still under development.

Finally, Miguel points out that at least two games are running on Chrome using Mono running under Native Mode. This is about the only serious alternative to compiling to JavaScript. Native mode allows compiled programs to run in the browser and there is nothing to say that the program that runs can't be an implementation of the .NET runtime. In this case the C# program runs in the browser as it would on the desktop. A very odd idea. Unfortunately the problem is that only Chrome supports native mode and the moment and it doesn't work on Android or iOS.

 csharpbrowsers

More Information

2012 Update: Running C# on the Browser

JSIL

Saltarelle Compiler

Related Articles

Dart + Chromium = Dartium

Pit - F# to JavaScript Compiler

JavaScript JVM runs Java

 

espbook

 

Comments




or email your comment to: comments@i-programmer.info

 

To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter, Facebook, Google+ or Linkedin,  or sign up for our weekly newsletter.

 

Banner


O'Reilly Data Reveals Surge In AI Learning
08/01/2025

The O'Reilly Technology Trends for 2025 Report is based on annual usage data from O’Reilly’s online learning platform data. It reveals a "dynamic landscape of developer learning", with AI tec [ ... ]



The State Of JavaScript 2024
01/01/2025

The 2024 State of JavaScript Survey was conducted between November 13 and December 10 2024 and the results are already out. The survey should possibly be renamed to refer to TypeScript - but remember  [ ... ]


More News

 

Last Updated ( Friday, 07 September 2012 )