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.
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.
More Information2012 Update: Running C# on the Browser Related ArticlesPit - F# to JavaScript Compiler
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.
|
Last Updated ( Friday, 07 September 2012 ) |