Click here to Skip to main content
15,887,318 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Good day everybody,

I've recently switched to Linux Mint as my primary operating system (actually I'm still trying it in a Virtual machine, but I'm going to install it on my computer very soon), so I am not an expert in that field.

I'm doing a school project for my last year of Liceo and I'd like to develop it in Linux with C# and Mono by using the IDE MonoDevelop which is told to cross compile the code for Linux and Windows.

According to this StackOverflow answer and some other resources I found out that MonoDevelop generates an executable for Windows and that if I copy the executable on the Windows machine it should work without problems. Actually, I tried it but nothing: the application runs smoothly in Linux (and it also opens a terminal window, which is something very annoying and I'd like to turn that off), but if I copy it on my Windows 10 system it does not work: after three seconds the process stops and the fact that the process has been started can be seen only in the task manager.

As I have Visual Studio 2015 installed on my system I expect to have installed also the latest version of the .NET framework so, according to the aforementioned article the executable should work, but actually it does not on Windows.

The project was compiled by using the GTK# graphics libraries on Linux.

Any help is appreciated.

Thanks a lot.

EDIT2: I've tried again by creating a new application in Mono, building it and then running it on Windows. It does not work, but I noticed something in my Mono References I haven't noticed before: no GTK# assemblies are found, though the application runs smoothly on Linux.
Here's a screenshot: Screenshot

EDIT: Here's the code I've tried: it's just a simple application that displays a text file in a textview (I wanted to try with something simpler before starting developing a bigger project):
C#
using System;
using Gtk;

public partial class MainWindow: Gtk.Window
{	
	public MainWindow (): base (Gtk.WindowType.Toplevel)
	{
		Build ();
	}

	protected void OnDeleteEvent (object sender, DeleteEventArgs a)
	{
		Application.Quit ();
		a.RetVal = true;
	}

	protected virtual void OnOpen(object sender, System.EventArgs e)
	{
		// Reset the logTreeView and change the window back to original size
		/*int width, height;
		this.GetDefaultSize( out width, out height );
		this.Resize( width, height );*/

		
		logTextView.Buffer.Text = "";

		// Create and display a fileChooserDialog
		FileChooserDialog chooser = new FileChooserDialog(
			"Please select a logfile to view ...",
			this,
			FileChooserAction.Open,
			"Cancel", ResponseType.Cancel,
			"Open", ResponseType.Accept );

		if( chooser.Run() == ( int )ResponseType.Accept )
		{
			// Open the file for reading.
			System.IO.StreamReader file =
				System.IO.File.OpenText( chooser.Filename );

			// Copy the contents into the logTextView
			logTextView.Buffer.Text = file.ReadToEnd();

			// Set the MainWindow Title to the filename.
			this.Title = "Nate's Log Viewer -- " + chooser.Filename.ToString();

			// Make the MainWindow bigger to accomodate the text in the logTextView
			this.Resize( 640, 480 );

			// Close the file so as to not leave a mess.
			file.Close();
		} // end if
		chooser.Destroy();
	} // end method OnOpen

	protected void OnClose (object sender, EventArgs e)
	{
		int width, height;
		this.GetDefaultSize( out width, out height );
		this.Resize( width, height );

		logTextView.Buffer.Text = "";

		// Change the MainWindow Title back to the default.
		this.Title = "Nate's Log Viewer";
	}

	protected void OnExit (object sender, EventArgs e)
	{
		Application.Quit ();
	}

	protected void OnAbout (object sender, EventArgs e)
	{
		// Create a new About dialog
		AboutDialog about = new AboutDialog();

		// Change the Dialog's properties to the appropriate values.
		about.ProgramName = "Nate's Log Viewer";
		about.Version = "1.0.0";

		// Show the Dialog and pass it control
		about.Run();

		// Destroy the dialog
		about.Destroy();
	}
}


GL
Posted
Updated 7-Dec-15 8:37am
v3

1 solution

You did not provide any relevant information on the project, so I cannot give you a recipe to overcome the problems, but there are things you need to understand correctly.

First of all, this is not cross-compilation. This is the compilation using different compilers for the same platform. .NET CLR and Mono are different implementations of the same platform. The fact that the assembly runs in the same way without recompilation is just one of the aspects of this fact.

At the same time, there is a number of incompatibilities between those implementations I've personally detected for different versions. I haven't use Mono for a while and cannot tell you any detail on the latest versions. However, all incompatibilities I saw are related to the implementation of some FCL types, and some, but very few of them were related to BCL. For example, I saw considerable incompatibilities in Form rendering.
(Please see:
https://en.wikipedia.org/wiki/Standard_Libraries_(CLI)#Base_Class_Library[^],
https://en.wikipedia.org/wiki/Framework_Class_Library[^].)

By the way, the violations of the standard was on both sides, on Mono and on Microsoft's. When Microsoft's implementation was buggy (I faced at least one such case) and the bug was fixed in Mono, it created the incompatibility.

I did not find the incompatibilities between Mono implementations for different OS (I used Windows, Linux and Mac OS X), but some differences between runtime behaviors on different OS are unavoidable. In particular, the part of system architecture related to the "console" are very different in Linux and Windows. Command line interface is very fundamental for Linux (and any kind of *NIX), but not for Windows.

Also, the notion of "console application" in .NET is expressed in a very confusing way, especially in Visual Studio. I don't remember how it looks for MonoDevelop, but its design is very similar to VS. The confusion leads to thinking that the applications are classified into "Window applications" and "console application". This is not so. In reality, the switch simply says that the console should be shown or not. If the application is "console", the console is always shown, but the application can be a Windows application at the same time, or console only, or anything. If the application type is not "console" (and not the library), the console is just not shown, but it may show a window, or nothing. Note that in all these cases you can use System.Console.Write, only the result of such output is not visible without console.

I've developed and tested a number of, say, System.Windows.Forms applications which worked on Windows .NET, Linux via Mono and Windows via Mono in nearly the same way. They did not show any console on any of the three platforms; and the same story was with Mac OS X. You should just do right thing: locate appropriate "application type" switch and use it the way you want.

I hope my notes can help you to sort out the problem with redundant/annoying console. You did not provide any relevant information which could help me to advise on other problems you faced. Perhaps you should utilize early prototyping and testing before developing bigger applications.

—SA
 
Share this answer
 
Comments
LLLLGGGG 7-Dec-15 13:51pm    
Thanks for your help.

The project I'm working on is about cryptography, but before starting developing it I tried with a simple GTK# application that simply reads a text file and displays it in a textview.

I'm going to post the code soon.
Sergey Alexandrovich Kryukov 7-Dec-15 14:14pm    
Please do it only in the body of your question, using "Improve question", not in any other way. Use proper formatting, <pre lang="cs"> ... <pre>...
Don't put your current code, instead, develop a test application of minimal possible size, focusing on only one problem, remove everything unrelated to your complain.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900