How to Host an ASP.NET Application with Mono - Part 2: Hosting on Mac OSX

In Part 2 of our three part series, we will cover running ASP.NET applications on Mac OSX.  Keep in mind that Mono doesn't currently support .NET Framework 4.5, so follow the instructions in Part 1 of this series if you need to downgrade to .NET Framework 4.0.

 

ENVIRONMENTS AND SOFTWARE VERSIONS USED

  • Operating Systems - Windows 8.1, Mac OSX 10.9.5, Ubuntu Server 14.04 LTS (HVM)
  • Mono 3.12.0
  • Visual Studio Community 2013 Version 12.0.31101.00 Update 4
  • ASP.NET MVC 4
  • Apache 2.4
  • VMware Fusion 7.1.1

We are using an iMac as our development machine.  It is running OSX 10.9.5 and has VMware Fusion installed.  We have a Windows 8.1 64-bit VM that we access through Fusion.  The Windows 8.1 VM has Visual Studio installed and that is where we wrote our ASP.NET MVC WebApi application.  Visual Studio Community 2013 defaulted to .NET framework 4.5 when we created the new project.   We quickly realized that Mono 3.12.0 does not support .NET framework 4.5.  It does support .NET framework 4.0 and this is where our fun began.  Follow the instructions in Part 1 of this series if you need to downgrade to .NET Framework 4.0.

 

INSTALLING MONO ON MAC OSX

Now that we have a ASP.NET MVC 4.0 application we can deploy that code to a Mac OSX machine and ensure that Mono will allow that application to run.  We followed the Install Mono on Mac OSX instructions on the Mono site.

We installed the .pkg and followed the installation wizard.  Then, we tried to run through the Hello World examples to ensure they were working.  All of the sample programs ran without error except for the Gtk# Hello World example.  We noticed this error:

System.DllNotFoundException: gtksharpglue-2
at (wrapper managed-to-native) Gtk.Container:gtksharp_gtk_container_get_focus_child_offset ()
at Gtk.Container..cctor () [0x00000] in <filename unknown>:0

We were able to fix this error by adding the following lines to the /Library/Frameworks/Mono.framework/Versions/3.12.0/etc/mono config file:

<dllmap os="osx" dll="glibsharpglue-2" target="/Library/Frameworks/Mono.framework/Versions/Current/lib/libglibsharpglue-2.so" />
<dllmap os="osx" dll="gthread-2.0.0" target="/Library/Frameworks/Mono.framework/Versions/Current/lib/libgthread-2.0.0.dylib" />
<dllmap os="osx" dll="gthread-2.0" target="/Library/Frameworks/Mono.framework/Versions/Current/lib/libgthread-2.0.dylib" />
<dllmap os="osx" dll="glib-2.0.0" target="/Library/Frameworks/Mono.framework/Versions/Current/lib/libglib-2.0.0.dylib" />
<dllmap os="osx" dll="glib-2.0" target="/Library/Frameworks/Mono.framework/Versions/Current/lib/libglib-2.0.dylib" />
<dllmap os="osx" dll="glibsharpglue-2" target="/Library/Frameworks/Mono.framework/Versions/Current/lib/libglibsharpglue-2.so" />
<dllmap os="osx" dll="gtksharpglue-2" target="/Library/Frameworks/Mono.framework/Versions/Current/lib/libgtksharpglue-2.so" />
<dllmap os="osx" dll="gobject-2.0.0" target="/Library/Frameworks/Mono.framework/Versions/Current/lib/libgobject-2.0.0.dylib" />
<dllmap os="osx" dll="gobject-2.0" target="/Library/Frameworks/Mono.framework/Versions/Current/lib/libgobject-2.0.dylib" />
<dllmap os="osx" dll="gtk-quartz-2.0.0" target="/Library/Frameworks/Mono.framework/Versions/Current/lib/libgtk-quartz-2.0.0.dylib" />
<dllmap os="osx" dll="gtk-quartz-2.0" target="/Library/Frameworks/Mono.framework/Versions/Current/lib/libgtk-quartz-2.0.dylib" />

 

RUNNING ASP.NET MVC 4.0 APPLICATION ON MAC OSX

With the sample programs working it was time to try out my MVC application.  We deployed the code from the Windows 8.1 VM to a new folder on the iMac.  Then, opened terminal and ran this:  

xsp4 --root <<parent folder path to the MVC bin folder -- do not include /bin in path>> --port 9000

While the xsp server is running you can test your application using http://localhost:9000/api/test url.  Replace "test" with the name of your controller.

Please stay tuned for Part 3 of this topic where we explore hosting an ASP.NET application on Linux.  

@bloomspire