BlogEngine.NET 1.3 was released just before Christmas. This version supports Mono on Linux out of the box, so if you've been waiting to try it on Linux, I would suggest you try it right away!

If you are about to run on Linux, I would suggest that you get the latest sources as there were a few late fixes for the new Extension Manager on Mono. You need to get version or later. As for Mono, you also need to get the latest version (1.2.6 as of writing), as the latest release has some major performance enhancements that are required for a stable Mono/BlogEngine.NET environment. See this post for more information.

With the Website Template in Visual Studio, all classes in the App_Code directory of your web site is compiled into a temporary assembly of its own when the web app is loaded by IIS. In order to get a handle to the assembly, you can use the following code snippet:

Assembly a = Assembly.Load("__code");

Of course, in Mono it doesn't work that way. To get the temporary compiled assembly you need to use the following:

Assembly a = Assembly.Load("App_Code");

Note that like everything on Linux, the casing matters here!  "app_code" will not work, unless you're running XSP on Windows.

Strangely enough the Mono implementation makes more sense. I couldn't find any information on the interwebs about this issue, so I eventually got it by guessing the correct name!

Not being able to trace through your code while doing a Mono port of an ASP.NET application can seriously hamper productivity. Until the Mono debugger is finally ready for prime time, we'll have to debug the old-school way.

One easy way of getting debug output from a Mono application is to simply use Console.WriteLine. If you're running your ASP.NET application through XSP2, the console output will be visible from the terminal that XSP was run in.

.NET supports using TraceListeners for capturing System.Configuration.Debug output. There is a handy ConsoleTraceListener that will convert all calls to Debug.WriteLine to console calls. This would be fantastic for Mono usage, but alas, Mono does not appear to support TraceListeners at all! My tests have shown that the overridden abstract methods in a TraceLister descendant are never called.

UPDATE: Seems my assumptions about TraceListeners not working in Mono was a bit premature, but not all that far off the mark.

As it turns out, TraceListeners do work, but only when you're running an application that has debugging enabled. This is the expected behaviour, and .NET follows the same guidelines.

However, when running a "Web Site" project (one that hasn't been pre-compiled), Mono still seems to have some issues. If you set the <compilation debug="true"> flag in the Web.config file, the application should be build with debug symbols and all debug output should function as expected. I've confirmed this to work on .NET, but am unable to get this working with XSP2 (Windows or Linux). The debug output does work however if you use a pre-compiled web site (i.e. ASP.NET Web Application in Visual Studio) compiled under the Debug configuration.

The Mono ASP.NET page suggests doing the following:

$ MONO_OPTIONS=--debug xsp2 
Listening on port: 8080 (non-secure) 
Listening on address: 
Root directory: /tmp/us 
Hit Return to stop the server.


This hasn't worked for me however. If anyone knows what I'm doing wrong here, please drop me a line and let me know!

I just came across the official mono porting ASP.NET applications guide. If you're planning on doing a port, I'd suggest you give this guide some attention.

The guide has some real gems like the following:


On Unix systems, Mono supports an I/O compatibility mode which allows you to ignore the file name case when accessing files on disk. The mode also takes care of disk designators (e.g. c:). Enabling the translation carries, obviously, some performance penalty, but is a good way to get your application up and running quickly. To enable the compatibility mode, make sure your web server's (XSP's or Apache's) environment contains the MONO_IOMAP variable set to all:



If you're using mod_mono, put the following line in your virtual host config file:

MonoSetEnv MONO_IOMAP=all


Knowing about this would have saved me a good couple of hours on the BlogEngine.NET port!

Something that will come in handy while porting applications to Mono is the ability to detect whether an application is running under Mono or .NET, and also whether it's running on Unix or Windows. While one would hope that .NET applications would be completely binary portable, there are still some situations where Mono's infancy becomes a stumbling block.

From the Mono Project Technical FAQ:

Having code that depends on the underlying runtime is considered to be bad coding style, but sometimes such code is necessary to work around runtime bugs.

The following methods are documented in the FAQ, but to save everyone time, I'll document them here.

Detecting Mono:

 1: using System;
 3: class Program {
 4:  static void Main ()
 5:  {
 6:  Type t = Type.GetType ("Mono.Runtime");
 7:  if (t != null)
 8:  Console.WriteLine ("You are running with the Mono VM");
 9:  else
 10:  Console.WriteLine ("You are running something else");
 11:  }
 12: }

Detecting Linux/Unix:

 1: using System;
 3: class Program {
 5:  static void Main ()
 6:  {
 7:  int p = (int) Environment.OSVersion.Platform;
 8:  if ((p == 4) || (p == 128)) {
 9:  Console.WriteLine ("Running on Unix");
 10:  } else {
 11:  Console.WriteLine ("NOT running on Unix");
 12:  }
 13:  }
 14: }

I apologize for the bad code formatting above, but I'm still fighting to get proper syntax highlighting working with Live Writer and BlogEngine.NET.

Ok, so judging by the amount of time it took for this next post to materialize, one could guess that I wasn't all that lucky in my Mono endeavour. You'd be right. Turns out BlogEngine.NET isn't Mono compatible. Or one could say that Mono's version of ASP.NET isn't ready for prime time yet.

Either way, it's taken me quite a bit of effort to get where I am today. Currently I'm writing this post via Mono/XSP on Windows, so I've clearly made some real progress. The next step is getting this running on my Linux server. As I'm a bit of a Linux noob, that could take a couple of days to happen too.

I've documented all the changes I've made to BlogEngine.NET, so I'll be posting an article with those changes sometime soon

I am a software developer / architect currently interested in combining .NET technologies with open-source operating systems. 

I am a member of the open-source BlogEngine.NET development team and focus mainly on ensuring Mono compatibility for the project.



At StayUnlimited Cape Town accommodation we help you choose from and book guest houses, self catering apartments, bed & breakfasts, luxury villas and hotel accommodation.