1

I downloaded a few source codes containing C# code that uses windows forms. Is it possible to compile the codes under the Linux environment (Ubuntu 12.04) and run it?

I already tried successfully to compile a few C# source codes with mcs and run the resulting exe file with mono.

The source codes can be downloaded here. If it's possible please describe how would you compile and run chapter 2/OpeningDocument solution.

$ mcs Program.cs 
Program.cs(3,14): error CS0234: The type or namespace name `Windows' does not exist in the namespace `System'. Are you missing an assembly reference?
Compilation failed: 1 error(s), 0 warnings

EDIT

$ gmcs -pkg:dotnet Program.cs 
Program.cs(17,33): error CS0246: The type or namespace name `Form1' could not be found. Are you missing a using directive or an assembly reference?
Program.cs(17,25): error CS1502: The best overloaded method match for `System.Windows.Forms.Application.Run(System.Windows.Forms.Form)' has some invalid arguments
/usr/lib/mono/gac/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll (Location of the symbol related to previous error)
Program.cs(17,25): error CS1503: Argument `#1' cannot convert `object' expression to type `System.Windows.Forms.Form'
Compilation failed: 3 error(s), 0 warnings
4
  • Yes it's possible. Works just the same as the rest. mcs and you're done. Why ask if you haven't tried? Commented Jun 12, 2012 at 16:42
  • Well the error seems pretty obvious: you are missing assembly references. Commented Jun 12, 2012 at 16:45
  • Mono does not support WPF applications. The zip file you linked to also would not open. Commented Jun 12, 2012 at 17:15
  • @Ramhound The zip file is OK. Cicada answer works. Commented Jun 12, 2012 at 19:30

2 Answers 2

4

If you're not using the latest version of Mono, this should work:

gmcs -pkg:dotnet *.cs

The latest version of mono uses mcs instead of gmcs. In the previous ones, mcs targets .NET 1.1.

Sign up to request clarification or add additional context in comments.

4 Comments

You are not compiling Form1.cs. Replace Program.cs with *.cs to compile all your C# code, else just write the list of files to compile.
Thanks a lot, I'm just starting with it, so I'm rather asking first if it has even sense.
@user7236293 Does the Mono Compiler Recognize all the needed files like the config file,the Form1.Designer.cs etc if i use the approach you have mentioned
Just in case: On CentOS 7 I faced the same problem. After installation of package mono-data-oracle it worked as shown.
2

You may wish to run your code against the mono migration analyser to see what fails or isn't supported. You can find the tool here: http://www.mono-project.com/MoMA. NOTE For the tool to work you will need access to a windows machine.

You can also take a look at current mono compatibility with various .Net features at http://www.mono-project.com/Compatibility.

Specifically for windows forms see: http://www.mono-project.com/WinForms

Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.