Can you run programs made with C#?


19 posts
by leimich » Fri Nov 02, 2012 7:24 am
Nothing happens when a C# exe is opened/run in GUI. If I use command line I get "Permission denied" error.

I finally found instructions how to install mono. Here
viewtopic.php?f=34&t=7631
I made a simple C# exe with Visual Studio Express, it has a Pushbutton and a Label. Not too much? Or should it be only CLI only?
Posts: 19
Joined: Wed Oct 17, 2012 2:24 pm
by leimich » Fri Nov 02, 2012 8:50 am
I have to answer myself when no one else will. Only a console or text only C# program will run. Not much fun in that.

I made the exe file with Windows Visual studio Express 2010 and copied it in to the Raspberry. Then I had to change Propertions/Permission to executable. After that it ran. But only in text mode. A simple GUI program gave me a long list of errors.

I hope this helps someone. There is not much joy in text mode programs. And what I know (young) students like graphical/GUI programming, made with an IDE. And thats what I'll teach. With or without Raspberry.

Leif M
Posts: 19
Joined: Wed Oct 17, 2012 2:24 pm
by mahjongg » Fri Nov 02, 2012 9:32 am
It doesn't run .exe files period!

.exe files contain x86 (intel) code, that cannot be executed with the ARM cpu in the RasPi.
User avatar
Forum Moderator
Forum Moderator
Posts: 6037
Joined: Sun Mar 11, 2012 12:19 am
by leimich » Fri Nov 02, 2012 9:49 am
mahjongg wrote:It doesn't run .exe files period!

.exe files contain x86 (intel) code, that cannot be executed with the ARM cpu in the RasPi.

I understand, but that is what I copied into Raspberry. What I know, .Net exe files are not what they look like. They (sometimes?) contain code which is compiled just before execution. The size of exe is just 4k or so. One reason I am not so fond of .NET, I like proper exe files.

If you tell me how to do a screen capture of Linux CLI, I can put it here to prove it.

Edit: fixed a typo.
Posts: 19
Joined: Wed Oct 17, 2012 2:24 pm
by leimich » Fri Nov 02, 2012 9:56 am
mahjongg wrote:It doesn't run .exe files period!

.exe files contain x86 (intel) code, that cannot be executed with the ARM cpu in the RasPi.

I learnt it here:
viewtopic.php?p=125064#p125064

"
You can build Mono applications on another machine (like a Windows PC), as long as the build options are set to produce platofrm independent IL code and then simply copy the EXE file. If you have dependencies other the Mono framework which are platform dependent then you may have to copy the project to the Pi and build on the command
Posts: 19
Joined: Wed Oct 17, 2012 2:24 pm
by Heater » Fri Nov 02, 2012 10:08 am
A C# exe may not be x86 code at all. Rather it is the stuff that is interpreted by the .NET run time. Rather like Java and it byte codes. In that way I have compiled many C# command line programs on Windows that run fine on Linux/ARM.

Command line C# programs compiled to .exe should just work on Raspian under mono no matter where they were compiled.

Be sure you will have problems with C# GUI programs moving from Windows to Linux. The GUI support is somewhat lacking or at least different.

Have you had a look at Mono Develop? It's a while since I have tried this out but it is possible to create GUI apps in C# that run on Linux with Mono Develop. What I tried a few year back worked very well.

I would suggest not using Windows as your dev environment if you are targeting the Pi. Or at least use MonoDevelop on Windows. That way you can be sure to keep away from any Windows specific features in your programs.

There is not much joy in text mode programs.


That is so untrue...
Posts: 1323
Joined: Tue Jul 17, 2012 3:02 pm
by leimich » Fri Nov 02, 2012 10:19 am
A C# exe may not be x86 code at all. Rather it is the stuff that is interpreted by the .NET run time. Rather like Java and it byte codes. In that way I have compiled many C# command line programs on Windows that run fine on Linux/ARM.
Yes, that's what I think too.

Or at least use MonoDevelop on Windows.
Is that possible, interesting. I'll try it. Can I make a graphical/ GUI program and transfer that into Raspberry. That would be nice.

There is not much joy in text mode programs.



That is so untrue...
Heh.

Thank you for an interesting post.
Posts: 19
Joined: Wed Oct 17, 2012 2:24 pm
by Twinkletoes » Fri Nov 02, 2012 10:35 am
As a C# expert, successfully running GUI programs on the Pi...

Think about how Java works - the compiler emits code for a processor that doesn't exist. A virtual machine on the target device then recompiles that for the target processor. Generally it does it as the code runs, so the first time a line of code runs it's compiled first, then the compiled version runs next time.

.Net is the same as Java in this respect, except that the IL (intermediate language) that's actually in the DLL or EXE can be compiled from multiple languages. Hence... C#, F#, Java.Net, Pascal.Net, Cobol.Net, Managed C++, VB.Net...

You can even take a C# class in a dll and make a subclass in Cobol.Net and then override a method in Java.Net if you're not given the original source code.

So when it comes to the Pi...

Mono 2.0.8 and Mono 2.10 run perfectly well on Squeeze. You'll have to wait for 2.12 to get hard float support (required for Wheezy), which breaks a LOT of stuff in Mono. That should be out by Xmas.

The ONLY thing in .Net 4.5 that is not supported is WPF and WWF (http://www.mono-project.com/Compatibility). Just about everything else works beautifully, including most Windows APIs which have been made to work on Linux.

Use MoMA to analyse your code - it will tell you which individual lines of code are not supported in Mono and why (it may point you at a non-implemented part of mono which you can fix yourself) http://www.mono-project.com/MoMA

I'm happily running WinForms code and ASP.Net MVC3 on the Pi.
Posts: 210
Joined: Fri May 25, 2012 9:44 pm
by leimich » Fri Nov 02, 2012 10:50 am
VB.Net...
I thought so.

Mono 2.0.8 and Mono 2.10 run perfectly well on Squeeze. You'll have to wait for 2.12 to get hard float support (required for Wheezy), which breaks a LOT of stuff in Mono. That should be out by Xmas.

The ONLY thing in .Net 4.5 that is not supported is WPF and WWF (http://www.mono-project.com/Compatibility). Just about everything else works beautifully, including most Windows APIs which have been made to work on Linux.

Use MoMA to analyse your code - it will tell you which individual lines of code are not supported in Mono and why (it may point you at a non-implemented part of mono which you can fix yourself) http://www.mono-project.com/MoMA

I'm happily running WinForms code and ASP.Net MVC3 on the Pi.


We are using Raspbian “wheezy” now, because it was recommended for first OS.

This is interesting and useful, but requires a bit time to study. But anyway answers I looked for.
Thank you
Leif
Posts: 19
Joined: Wed Oct 17, 2012 2:24 pm
by BlackJack » Fri Nov 02, 2012 11:14 pm
@Heater: AFAIK a .NET exe always contains x86 code at the beginning. A little stub program that looks for the .NET runtime environment and starts it with the IL code coming after the stub or it displays an error message if there is no .NET runtime installed.

@Twinkletoes: Just like IL, bytecode for the Java Virtual Machine can be compiled from multiple languages and not just Java. Wikipedia has a list of JVM languages.
Code: Select all
while not self.asleep():
    sheep += 1
Posts: 288
Joined: Sat Aug 04, 2012 8:28 am
by 6677 » Sat Nov 03, 2012 4:02 pm
you have to specify to open your .exe with mono. Mono will ignore the x86 assembly at the beginning of the .exe
Posts: 382
Joined: Wed Mar 14, 2012 9:23 pm
by adwen » Sun Nov 04, 2012 5:06 pm
Mono 2.0.8 and Mono 2.10 run perfectly well on Squeeze. You'll have to wait for 2.12 to get hard float support (required for Wheezy), which breaks a LOT of stuff in Mono. That should be out by Xmas.


That is very sad news to hear. xmas is a long wait!

I have 2 questions about it.

1. Is this a problem with mono 2.10.8? Or can I build mono 3.0 to solve this problem? [if yes] I found the debian experimental sourcecode for mono 3.0 @. http://mono-project.com/DistroPackages/Debian . Can I use the source code the build it for the pi?

2. @twinkletoes. I'm curious to know how did you get your mono working? Does it really work flawlessly? I've installed mine it seems to be working with small test apps but it is really broken (for example if i use datetime)
Posts: 9
Joined: Sun Jul 08, 2012 5:51 pm
by pygmy_giant » Sun Nov 04, 2012 5:09 pm
xmas is a long wait!


not long enough for me.
Posts: 1569
Joined: Sun Mar 04, 2012 12:49 am
by 3gws » Sun Nov 04, 2012 5:50 pm
Adwen, I read somewhere there is an issue wit Date time with Mono on the Raspberry Pi.

3gws
Posts: 49
Joined: Sat Oct 20, 2012 10:32 am
by 3gws » Sun Nov 04, 2012 5:54 pm
twinkletoes, is it fair to say then, that Mono winform apps WON'T/DON'T work on Wheezy !.

3gws
Posts: 49
Joined: Sat Oct 20, 2012 10:32 am
by adwen » Mon Nov 05, 2012 6:18 pm
So, I'm wondering where can I find a definitive answer on the matter. What are the proper channels to ask these sort of questions?
Posts: 9
Joined: Sun Jul 08, 2012 5:51 pm
by Twinkletoes » Mon Nov 05, 2012 7:20 pm
Definitive answer:
Mono 2.10 runs very well on Squeeze. Use the mono tools to determine whether your app will work. Standard win forms should be fine. Wpf definitely won't work. .net 3.5 should work fully as should 4.0. 4.5 missing things like async keyword.

On wheezy nothing non-trivial works in my experience. You will need mono 2.12 for this.
Posts: 210
Joined: Fri May 25, 2012 9:44 pm
by 3gws » Mon Nov 05, 2012 10:50 pm
Twinkletoes, thanks for your answer.


3gws
Posts: 49
Joined: Sat Oct 20, 2012 10:32 am
by stephj » Fri Nov 23, 2012 4:53 pm
The x86 code at the start of every .exe file is a hangover from the days of good old fashioned DOS. If it is run under a DOS environment it spits out the message:-

"This program cannot be run in DOS mode." and then immediately terminates.

Windows .exe files are in PE format (Portable Executable) which is a version of COFF (Common Object File Format) that Unix/Linux variants use, which explains why simple .NET programs will run on the pi under Mono.

Headers within PE/COFF files inform the OS what is in it, and chain along to other headers dependant on those encountered previously.

If it is a .NET program then one of the headers encountered will be a CLR Header which will itself link the to the chunk of IL code to be run. IL is like Java byte code, it is a machine independent stack based language.

The .NET or Mono CLR will take this code and attempt to Just-In-Time compile it down to executable machine code to do the job of the IL and then run it under the .NET/Mono framework installed on the machine. If it works, so and good otherwise it will report an error,(which may or may not have anything to do with the original error), and then terminate.

If it is a native program then the headers describe what class of processor it was built for, and whether it is 32 or 64 bit etc., and of course where it starts and finishes. If the object code matches the current OS/Processor the loader will initialise it, and pass control to the start address.

I have written .NET programs for Windows Mobile 6.0 devices (ARM processor), where exactly the same .NET executable will run under Windows on a PC (x86)
User avatar
Posts: 33
Joined: Thu Jun 21, 2012 1:20 pm
Location: Bolton, UK