It's my understanding that C#, though created by Microsoft, is a programming language that can be used or implemented for things other than .NET programming. For example, I could create a compiler for C# to target native x86 or other processors or even a JVM. Is my understanding incorrect? Does anyone know if C# is used for anything besides .NET?
C# is used for an experimental operating system called 'Singularity' which is written in the managed level from the ground up. An interesting project to watch!
Edit: Thanks Jörg W Mittag for his comment - Helios is actually a modified form of Singularity to support satellite kernels, to quote from the paper I am reading right now 'Helios is an operating system designed to simplify the task of writing, deploying and tuning applications for heterogenous platforms. Helios introduces satellite kernels, which export a single uniform set of OS abstractions across CPUs of disparate architectures and performance characteristics. Satellite Kernels allows developer to write applications against familiar operating system APIs and abstractions.'...interesting...
Hope this helps,
Best regards,
Tom.
You are correct that it can be used for other things. It's a language specification...you can compile it into anything you like if you take the time, but it'd be a tremendous effort.
I don't know of any other uses besides Mono as jrcs3 said, but hopefully Eric Lippert will chime in and give you a compiler point of view on C#
C# itself is a specification specified by the ECMA that "specifies the form and establishes the interpretation of programs written in the C# programming language." as is the CLR. The most popular implementation of these is currently provided by Microsoft, which is the C#.net that you know. C# and the CLR are open standards, meaning that anyone can implement them themselves, hence the formation of mono, a C# compiler for mac/linux. Compare this to java, who's only implementation is provided by sun. It's not an open standard, so you can't create your own implementations.
from wikipedia:
Mono "An open source, cross-platform, implementation of C# and the CLR that is binary compatible with Microsoft.NET"
DotGNU "is a part of the GNU Project that aims to provide a free software replacement for Microsoft's .NET Framework"
Dot Net Anywhere is a .net CIL interpreter for targeting embedded systems.
As far as I'm aware, all currently existing implementations of C# build to CIL and run in the .NET CLR or compatible environment, and the only alternative to the .NET CLR I am aware of is Mono.
In other words, all current versions of C# build to run in .NET or Mono.
.NET and Mono use the same 'binaries', so effectively all current C# compilers have only one target.
Another area of use is for iPhone app development (and I believe iPad now as well) via MonoTouch.
What is MonoTouch?
MonoTouch allows developers to create C# and .NET based applications that run on Apple's iPhone and Apple's iPod Touch devices, while taking advantage of the iPhone APIs and reusing both code and libraries that have been built for .NET, as well as existing skills.
Roughly speaking, it goes like this:
MonoTouch -> MonoDevelop/C# -> write an iPhone app -> compiled to native code -> iPhone app.
Relevant links:
MonoTouch
Writing your First IPhone application in C# using MonoTouch
Note that Unity 3D also allows "C# Scripts", and compiles to target Mac, Windows, Web, Wii and iPhone (and therefore iPad).
There are indeed tools to convert a .NET assembly to a standalone executable or library, so that you don't need your clients to have the .NET framework. This also further protects your code against reverse-engineering to some degree -- you can't use Reflector to see the .NET source on a native binary.
See Remotesoft Salamander .NET Protector, for instance.
But, that isn't strictly C# -> native; Salamander converts the MSIL to native code.
On the other hand, there is at least one academic project on making a C# -> native compiler using LLVM, called LLVM#.
You can compile a C# program on Mono. But that probably doesn't count.
Mono is an alternative implementation of the Common Language Infrastructure (CLI) that runs on Linux and various other operating systems. As mentioned in other places, both C# and the CLI are ECMA standards and can be implemented by anyone who cares to do so.
Rotor is another non .NET implementation.
You can use it on iPod apps if you use MonoTouch.
Related
I have a C++ game engine that currently supports Windows, Linux and Android (NDK). It's built on top of SDL and uses OpenGL for rendering.
One of the design constraints of this game engine is that the cost of development must be $0.00 -- building the engine should come at no cost to me (other than man hours), I must be allowed to freely redistribute the engine's code and binaries, and users should be able to sell games created using the engine with no restrictions.
Right now, I'm using a very slow interpreted scripting language for game logic -- it actually works well for writing glue code and simple responses to UI events, but not much else.
I'd like to replace this system with a C# solution -- have the user compile a C# class library (DLL) containing their game logic, and have the C++ side 'consume' this DLL and call the appropriate hooks.
It's been rather difficult to find information on how to achieve this in a cross-platform way. Each platform has a different way of hosting the needed runtimes. Also, most articles I've found suggest the use of full-fledged frameworks that provide platform abstractions that are already implemented in my engine.
Is there currently a way to run code from a C# DLL from an Android NDK-based C++ application without using an entirely different SDK, and without having to shell out hundreds of dollars for a license?
In particular, I'm eyeing some of Microsoft's recent open source .net initiatives -- anything there I could use?
EDIT: To clarify, Windows and Linux have well-documented ways of running .net code 'for free' -- this question pertains specifically to calling managed code from an Android NDK application WITHOUT paying licensing fees to Xamarin or another vendor.
It's been rather difficult to find information on how to achieve this in a cross-platform way...
I'm only going to address the issue of "write once, run everywhere."
I build and maintain a library, composed of a single set of sources, that runs on Windows, Linux, OS X, Windows Phone, Android and iOS. To do that, I had to write everything in portable C/C++, and then build DLLs or shared objects.
The project uses .Net interop to call into the DLL, and Android uses JNI to call into the shared object. On iOS a static library is created rather than a shared object.
The DLL or shared object does have some platform specific defines. For example, it must know how to get random numbers from the underlying OS. So it will have a function like:
bool GetRandomNumbers(unsigned char* ptr, size_t size)
{
#if defined(WIN32) || defined(WIN64)
...
#elif defined(__linux___) || defined(linux)
...
#elif defined(__ANDROID___)
...
#endif
}
So keep your core business logic portable and in a DLL or shared object, #define where you must to abstract platform differences, and you will be OK.
On top of the portable library, you layer the platform specific GUI stuff.
If you try to write this in C# and then use that on other platforms, you're just going to be causing yourself problems. The only way to do portability with a single set of sources is to use portable C/C++.
I've also seen folks re-implement in every language: C and Win32 for Windows, .Net for Windows, C for Linux, Cocoa for OS X, .Net for Windows Phone, Java for Android and CocoaTouch for iOS. That creates about 6x the work, and the behaviors are never quite the same across platforms.
A popular script engine for games is Lua; you might consider using that, since it's trivially easy to link with C/C++. If you use LuaJIT, it's also blazing fast on Android (and not shabby on iOS).
One alternative to consider is that if you build your custom engine on top of Cocos2d-X, you'd not only get Lua (or JavaScript) for free as a connected scripting engine, you'd also get portability to Windows (Win32 and Windows 8.1 Universal), iOS, Mac, and Linux, an IDE (!!), and a huge supportive community.
Or you can spend a lot of time figuring out how to integrate C# into your engine.
The simple answer is no, what you're looking for does not currently exist. You will need to drop/change requirements to find a solution.
The closest I know of is dot42 - which seems to support some of .net on android has recently been put on github and the main site shut-down - but there's no mention of license in the main compiler repository (I've added a bug to get that updated..)
It's not clear that it supports dynamic loading of C# .dll's though as it claims to compile to DEX. (But it may be free, depending on what the developers release as the license...)
Xamarin is the only other feasible alternative that I know of, but as you're aware only the starter edition is free.
If what you're after is purely better scripting support, I'd drop the compiled and C# requirements and find something that works well on android already. Lua is my go to solution for this kind of thing, but I've not used it on android before... and many other options exist.
I am creating a source code editor for Java using C# in .NET 4. I need to know how I can interact with the jre to compile the java code on my application editor interface from .net. I wish to display the user any errors on the code as well. Any ideas on how to accomplish this will be greatly appreciated.
Note that the JRE is the runtime, and as such doesn't come with the compiler. You will require the JDK to compile.
I think the simplest solution is to spawn off an instance of javac from within your .Net application. Perhaps a preferable solution (however) would be to write your app in Java itself, and you can then make use of the Java compiler API directly within your app.
Perhaps the most natural interoperability method is to run the Java code in a JVM, the .NET code in a CLR, and use a runtime bridge to manage the communications between them. In this scenario, the .NET code calls .NET classes and objects that act as proxies for the Java classes and objects. The proxies manage the communication; the calling .NET classes aren't even aware that they're ultimately calling Java classes. A runtime bridge provides interoperability for a wide variety of architectures, because the Java code and the .NET code can be on different machines, the Java code can run in a standalone JVM or in a Java EE application server, and the solution provides interoperability for any JDK version. As with bytecode translation solutions, you need only the Java bytecodes, not the source.
The code for this article uses JNBridgePro from JNBridge.
I have done a lot of research regarding this issue. but i am still confused in choosing the right programming language. I wanted to convert my system which is programmed using C# to a cross platform system. Even though c# is an cross platform language the mono project is not successful according to my research.
Please give me your suggestions to this problem? I believe c++ and java will be an ideal programming language but java doesn't provide good GUI and if i choose c++ i will get stucked when converting my dll to c++.
Please provide your suggestions. Thank you.
Since Java syntax is a lot like C# syntax it would be easier to convert the code to Java. And there are actually some nice GUI libraries for Java.
See which-gui-library-is-the-best-in-java (Deleted in the meantime but Swing and SWT were favoured there)
I don't know what you mean by a good GUI, but you could use SWT which gives native integration to file/Open dialog boxes etc, rather than using the Java ones.
Of course a lot depends on how cross paltform you need it to be. Some devices only support C.
"cross platform" is not a fixed term. For example: Using the Eclipse RCP you have SWT on board. Your code uses the RCP stuff and would be platform neutral. But the embedded SWT libs would require either per-platform installable packages or one big package containing the SWT libs for all supported platform. If this is OK for you, you could use Java+SWT+(anything else you want) and have nice GUIs.
There is NO truly cross-platform language or technique. Yes, Java and Python can provide some abstraction over a platform... But everything stuck if only you add ":" to your file-name.
I mean, creating a software that is truly runs on many platform is FAR more than only choosing between Java, C# and C++. If one developed such software, one would understand me...
There is NO problems with Mono if you consider Mono as a target platform from the beginning. The most problems with mono happens when something is already written in .NET without ever aimed to be run on Mono. In this case there could be problems. If you bare in mind Mono from the beginning it is still the excellent platform.
As something that wasn't suggested here yet, I could refer you using python with Glide as cross-platform solution of creating applications with GUI.
Or you can see the Vala GObject system. Which syntax is really C# alike.
I am confused as to what exactly .NET actually is. I am a Computer Science student who has done a lot of Win32 (WinAPI) programming in C++ & have a pretty good understanding of how Win32 functions interact with COM & the Windows Kernel itself.
But where does .NET fit into all this?
Specifically, if Win32 is an API written in C, what is .NET? Is it an API written in C also? Does it only run on Windows OS like Win32?
Does .NET run on top of the Win32 API? For example a .NET function showWindow() (I made that up obviously) call Win32 functions behind the scenes to show the window or does it go directly to the Kernel to do this? Or is .NET like the Java Virtual Machine?
Does .NET interact with the Windows Kernel directly (like Win32) & interact with COM objects? Does .NET run in a sandbox & not allow some access to certain OS areas?
I can code in different languages using the Win32 API such as c/c++, VB, Perl. What languages can I code in .NET?
This is what really stumps me. I hear about web applications written in .NET? What, how, wha? What language is it written in? Does .NET run on top of IE? Do .NET web applications work on Firefox or on Safari(MacOS)? Is a .NET web app like a java applet, do you get .NET drive bys too.
Some brief answers to keep you going:
Specifically, if Win32 is an API written in C, what is .NET? Is it an API written in C also?
.NET consists of multiple parts. One part is called the CLR. That part is written in C++, C++/CLI, and some assembly. This is responsable for Running the .NET appplications. The Just-In-Time (JIT) Compiler is an important part of this.
Then there are the included libraries. These are mostly written in C#, but some of them presumably have parts written in C++/CLI. You can actually get the source code for many of the included libraries.
Does it only run on Windows OS like win32?
Also no, there is a port that runs on Linux (called Mono), there is the version that runs on WIndows Phone 7, and then there is Silverlight which also runs on Macs....
Does .NET run ontop of the win32 API?
To a large degree, yes, although in some places it is starting to replace the regular WinAPI (it was certainly Microsoft's plan at one stage to try and .Net-ify most or all of the WinAPI). I wouldn't be writing drivers with it though, you will still use regular C/C++ interfacing to the Kernel API.
The libraries do make calls to many different portions of the win32 API. This is required to smoothly interoperate with other Windows Applications.
Does .NET interact with ... COM objects?
Yes it does, using COM interop.
Does .NET run in a sandbox & not allow some access to certain OS areas?
Some variants of the runtime can be sandboxed (Silverlight, WPF XBAP). .Net applications which possess the UnmanagedCode permission can also call code written in unmanaged C++ with full unfettered access to the system (you still have to abide by little pesky things like file ACLs though).
I can code in different languages using the win32 API such as c/c++, VB, Perl. What languages can I code in .NET?
.Net is a runtime library with JIT compilation. There are many languages you can use that are built on top of the framework. The JIT compilation is also not mandatory - you can still compile your applications to target a specific CPU architecture.
I hear about web applications written in .NET? What, how, wha? What language is it written in? Does .NET run ontop of IE? Does .NET webapps work on Firefox or on Safari(MacOS)?
Those applications can be written in any .Net language, although practically most of them will be using C# and VB.Net. You must have heard of ASP? Well, ASP.NET (and its sister ASP.NET MVC) is the next generation - this runs on the server and renders out HTML + javascript like many other server side languages. You also have the option of running Silverlight on the client, it can run both in and out of the browser. Silverlight most definitely works in Firefox, Safari and Chrome.
.NET is a MS brand for a CLI VM; there are CLI VMs for other platforms; mainly "mono"; however, even .NET is wider than just win32, since versions of .NET exist for XNA (xbox 360), mobile devices (CF), even smaller devices (MF), browsers (SL) and phones (WP7, etc). .NET is also sometimes used as the name of the library, and much of that is written in C#. In Windows 8 there is also WinRT which confuses things further.
(see the above, too) a mix of both; it has interop (P/Invoke) for when it needs OS features, but can be self-supporting too.
it is generally a VM, so yes it is a sandbox; note that some compilers exist (mono AOT) for compiling directly to native code, for example ARM for iOS devices (see: MonoTouch)
CLI compilers compiles to IL; there are many CLI compilers (and runtimes, for dynamic languages). IL is generally JIT'd to native code as-needed, but can be done ahead-of-time (NGEN), or not at all (MF is an IL interpreter)
the "web application" there is probably referring to the server part; this very site has a C#/.NET server implementation. There is also Silverlight and XBAP for in-browser client experience. Silverlight works on a number of browsers, as does moonlight (the mono version, for non-windows platforms).
There are several parts to what .NET is.
The runtime. This is written in C (AFAIK) - it is what .NET application run on. Has a garbage collector. This is what interacts with the Windows Kernel.
The BCL (Base Class Library) this is a set of .NET libraries. Some of these are wrappers over COM. Earlier versions had more COM wrappers than the later ones.
The CL/IL (Common Lanaguage/Intermediate Language). This is a low level language (similar to Java bytecode). Most .NET languages compile to this and this is what the runtime executes.
Microsoft has made parts of .NET into a standard - parts of which have been implemented for Linux with the Mono project.
You can interact with COM using .NET using pInvoke (Platform Invoke). In this respect, it is not sandboxed. This means you can call any PE style executable using .NET. And of course there is a myriad of languages that compile to IL (called .NET languages) - the best known are C#, VB.NET and F#, but there are implementations of python (Iron Pyton), COBOL and many more.
As for web applications - there are several web frameworks (ASP.NET and ASP.NET\MVC are the Microsoft created ones) that run on the IIS web server. .NET does not run in a browser, not natively, but the server generates HTML that the browser uses. As with all other web applications, if developed that way, they can work on all browsers.
You can use .NET in the browser using plug-ins (Silverlight and MoonLight are the best known).
The .NET Framework contains a run-time engine (JIT/Native Compiler) and has a large collection of libraries written primarily in C#.
This allows languages developed using Common Language Infrastructure (CLI is an open specification) to sit upon the framework as the compilers for each individual language compile the code into MSIL (Microsoft Intermediate Language) which the .NET Runtime engine executes.
Currently, Novel are developing Mono which is a cross platform Runtime Engine for .NET CLI Languages, but again it's still quite early on, Most of the .NET 3.5 Specification is implemented.
As far as "web apps" go, Applications developed in ASP.NET are all server side and serve back HTML and javascript to browsers in an attempt to emulate some WinForm style actions.
But Silverlight, is a browser plug-in for non-IE browsers which contains a cut down version of the .NET Runtime engine and libraries, which in-turn executes applications written in a .NET CLI Language on the local computer.
simply you can think of it as a wrapper for the win32 API's "actually it is!"
and also it is full framework that separate the programmer from the old API's and its problems
it has a run-time like java and it is capable of working in several platforms
and of course all if that is working above the windows API's
a simple article about dot net here
http://www.codeproject.com/KB/dotnet/allaboutnet.aspx
Why C# is an open standard but .NET is not? What is the point in this? Why Microsoft decide to open only some part of their .NET?
Various parts of the .NET runtime are indeed standardised by ECMA just like C# - CIL, the CLI, the CLS.
.NET is the runtime and C# is the language. C# can be compiled and run on other runtimes, such as Mono. I am actually not aware of any other runtimes besides Mono, but since the spec for C# is open, you could read it and make your own runtime. ;)
C#, like Java, C, C++, etc. is just a language definition. In and of itself, it does nothing. It defines the means by which a user can define a program or procedure and interface with external libraries.
The .NET framework, on the other hand, is not a language. It's a class library and development framework.
Actually, there is an open standard (ECMA 335 for the runtime api instead of ECMA 334 for the language).
Going beyond this, the source code for Microsoft's implementation of .Net is available and there are multiple separate implementations (the most prominent of which by far is mono).
There is some additional concern about patent encumbrance. However, Microsoft has also issued a legally binding and irrevocable community promise on the .Net platform that covers both specifications (a lot of people miss the legally binding part).
I assume you mean the framework. I guess they want to maintain control over the library implementation on Windows. There is nothing stopping someone from implementing a call-compatible version of all or part of the framework based on their own source as was done by Mono.