Category Archives: Computers

Mac OS X and Windows

Asp.Net MVC4 on Mono & Xamarin/MonoDevelop on Mac – The C# Template Project

Update Jan 2014: Go straight to github for MVC Templates for .Net 4 and .Net 4.5 or see asp-net-mvc4-net-framework-version-4-5-c-razor-template-for-mono-on-mac-and-linux for more recent notes.

I’ve been trying for a while to get this working. It all seemed so-near-and-yet-so-far. But here is the Visual Studio 2010 C# Asp.Net MVC4 Template Project which works on my Mac and (thanks to comment from Stephen) on Linux :
Visual Studio 2010 Asp.Net Mvc4 CS# Web Application Template modified for Mono

There’s a list of issues which frustrated earlier attempts but the above link is to a project that does build and run on my Mac. Things to make it work included:

  • Got the latest Xamarin Studio, previously known as MonoDevelop
  • Mono version: I got MVC4 on Framework version 4 running on Mono 2.10.12; and MVC4 on Framework 4.5 on Mono 3.2.5. Nb I’m not sure whether everything related to async is currently working, but many web apps wouldn’t want to use async.
  • There’s a list of potential issues to address described in this stackoverflow post, I think what I did was just:
    • Delete Microsoft.Web.Infrastructure.dll from the bin directory
  • I also removed Entity Framework References. As of Jan 2014 that’s not yet done on the Mono, although this may change shortly.
  • At first I commented out the line AreaRegistration.RegisterAllAreas(); in global.asax.cs Application_Start because it caused an error which appeared to refer to Entity Framework but that might just have been because I had removed System.Web.DynamicData too, so I put DynamicData back in.
  • The StyleBundles failed with a typo, or rather a case-sensitivity issue. A lot of .Net code is written on the assumption of a case-insensitive file system, but mono on *nix will usually have a case-sensitive filesystem, so you have to start being pedantic about getting the case correct. For instance App_Start/BundleConfig.cs referred to the file Site.css as site.css, so it wasn’t found until I corrected it.
  • Having taking the ‘intranet’ template which uses Windows authentication, I changed the web.config line <deny users="?"></deny> to <allow users="?"></allow>. But this gives you no security. The simplest route back to a secure website is to instead put in forms authentication, I don’t yet have a solution for windows authentication on mono.
  • I included all the nugetted package dlls in the zipfile, except that I deleted the EntityFramework stuff.

Kudos to all who worked so hard to make MVC4 on Mono possible. And of course to those who made MVC4 possible at all.

Visual Studio 2012 Command Prompt Here

Something I always want with VS projects: The ‘Command Line here’ menu option within Visual Studio; and the ‘Visual Studio Tools Command Line here’ option in Windows explorer. So here they are for VS2012.

NB: that the Explorer right-click works when you right click on a folder icon but not, sadly, when you right click on empty space. If anyone has a solution for that I’ll be glad to know.

Windows Explorer “VS2012 Command Prompt Here” Right-Click Menu Item

To add a Visual Studio 2012 Command Prompt Here to your Explorer Right-Click menu, save this as a .reg file to your desktop, and then run it:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\Command Line VS2012]
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\Command Line VS2012\command]
@="cmd.exe /k echo on & pushd \"%1\" & \"C:\\Program Files\\Microsoft Visual Studio 11.0\\VC\\vcvarsall.bat\" x86"

If you have 64-bit Windows, you might want:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\Command Line VS2012]
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\Command Line VS2012\command]
@="cmd.exe /k echo on & pushd \"%1\" & \"C:\\Program Files\\Microsoft Visual Studio 11.0\\VC\\vcvarsall.bat\" x64"

Visual Studio 2012 External Tools Command Prompt Here Menu Item

In visual studio choose TOOLS – External Tools. Press Add to add a new command with fields as follows:

Title: Command Line Here
Command: %COMSPEC%
Arguments: /K "%VS110COMNTOOLS%\VsDevCmd"
Initial Directory: $(ItemDir)

i.e.:

Visual Studio External Tools Command Line Here VS2012 Dialog Box

Sorted. You can add shortcut key to via TOOLS – Customize – Keyboard and setting a shortcut key for Tools.ExternalCommand{X} … but you have to work out by counting what number your {X} is.
Visual Studio Customize Keyboard Tools.ExternalCommandX Dialog Box

WCF on .Net 4.x ReST Service with IIS 7 or 8 = HTTP Error 404.17

So my newly created WCF ReST service (or webHttp service, as MS more accurately like to call it) runs fine in Visual Studio 2012, using IIS Express. But when I switch to IIS proper (in my case, IIS8 on Windows 8) I get:

HTTP Error 404.17 – Not Found
The requested content appears to be script and will not be served by the static file handler.

Most so-far extant posts on how to fix this, refer to how to fix it for .Net 3 on Windows before Win8: Use "%WINDIR%\Microsoft.Net\Framework\v3.5\Windows Communication Foundation\ServiceModelReg.exe" to register or to repair registration of WCF components. (The other gotcha being, having the right AppPool settings for .Net version & for 32 vs. 64 bit).
This doesn’t work for Windows 8 / .Net 4.X. Instead you must open the control panel “Turn Windows Features On or Off” and tick the box for Http activation:

Windows Features - Windows 8 - Net45 - WCF - Http Activation Tickbox

Windows Features – Windows 8 – Net45 – WCF – Http Activation

Which should fix the issue after a couple of minutes.

Can a Contract Cope with Changing Requirements?

It’s been decades since software people started to think about how to cope with requirements changing during the course of an engagement, though other areas of endeavour have surely been doing it since the stone age. Literally.

The state of the art for software, and increasingly for other areas of IT, is Agile. Yet the recognition of agile in contractual relationships has lagged behind, which is odd given that a large part of IT is done by contracting someone.

When all is sunshine and daises this doesn’t matter. The time you really really want your written agreements to be right is when things go awry. If you’re doing business even with friends & family, it can help to have something in writing.

But how to write a contract for something when you know it’s going to change?

This problem came up in a linked-in architects’ discussion and I immediately reached for google to find my notes from Susan Atkinson’s presentation on Agile Contracts (I saw her present at a Rational User Group conference a couple of years ago). I reduced it to bullet points in /p1201/susan-atkinson-features-of-an-agile-contract, and she was good enough to drop by to correct & update it. She’s been developing an Evolve Contract Model with Gabrielle Benefield and the website should be up soon. Meanwhile there is a recent presentation on slide-share at Contract Metrics For Agile.

For those not yet convinced that there’s anything wrong with a waterfall-style contract and project, you can read the IEEE 2013 conference paper at http://www.slideshare.net/SusanAtkinson2/ieee-2013-the-flaws-in-the-traditional-contract-for-software-development. nb Open it full-page mode for easy reading.