Running nuget on mono

Well the documentation states that the nuget command-line tool does indeed work with mono

Does NuGet support Mono?

The command-line application (nuget.exe) builds and runs under Mono and allows you to create packages in Mono.

So I merrily install nuget to my home directory ~/. Run the command mono ~/nuget and get the error message:


WARNING: The runtime version supported by this application is unavailable.
Using default runtime: v2.0.50727

Screen Shot 2012-05-06 at 11.04.32


Turns out the simple solution is to specify the absolute .net version:

mono –runtime=v4.0.30319 NuGet.exe

 and voila!

Screen Shot 2012-05-06 at 11.11.57

Tagged ,

Setting up a new project, from scratch on a blank machine as of 2012/02

  • Install loads of crap useful applications

Chocolatey packages

cinst 7zip

cinst console2

cinst ilspy

cinst kdiff3

cinst gitextensions

cinst resharper

cinst nuget.commandline


Configure git

Install stuff not yet on Chocolatey



Orchard CMS blogging with an iPhone

I’ve recently been evaluating the Orchard CMS project for an upcoming website I’m building for my award winning London diving club Smile . I thought it would be really useful to be able to blog to the website straight after a days diving whilst the excitement and pictures were still fresh off the press.


Step 1: Create your Orchard blog if it doesn’t exist already


Step 2: Turn on remote blog publishing



Step 3: Retrieve your blog id

Ochard’s remote blogging interface implements the MetaWeblog API. Whilst some clients such as windows live writer support self discovery using the real simple discovery mechanism. Your blog id is required by some iphone clients


Simple navigate to the following url: http://[path_to_your_blog]/rsd for my local development orchard install that was: http://localhost:30320/OrchardLocal/blog/rsd


Take a note of the blog id which in this case was 24


Step 4: Configure your iphone app

I was very surprised to find out how few generic iPhone blogging clients there are.  Whilst investigating this task I paid for and tried two apps:

  1. BlogPress – (very buggy, does not seem to work with Ochard)
  2. BloggerPlus – Does work!

Step 5: Configuring blogger plus to work with orchard


Step 6: Patching Orchard is required if v.1.3.10 or <

As of today 07/02/2012 my patch has not made it to the main Orchard code base, so if you are running Orchard v.1.3.10 or < you need to download this change set and rebuild orchard

Tagged , , ,

What is the current state of REST frameworks in .Net 4.0

WCF WebHttp Services in .NET 4

Part of the official .Net 4.0 framework release.

WCF WebHttp Services is the flavor of WCF that is most appropriate for developers who need complete control over the URI, format, and protocol when building non-SOAP HTTP services— services that may or may not subscribe to RESTful architectural constraints.



Introducing WCF WebHttp Services in .NET 4:

WCF WebApi

This project focuses on allowing developers to expose their apis for programmatic access over HTTP by browsers and devices.

Essentially this is a continuation of work done on the WCF Rest starter kit, and could be considered as a preview of wcf http services for .net 5.0?

WCF REST Starter Kit (depreciated)

The new WCF Web Api’s recently announced at PDC replace the REST Starter Kit and provide significant enhancements including better access to HTTP, more flexibility with representations and support for jQuery. Please go to for more information.


Open Rasta

OpenRasta is a development framework targeting the Microsoft .NET platform for building web-based applications and services, and distributed under an Open-Source MIT License.

By focusing development around resources and HTTP methods, OpenRasta simplifies the creation of ReST-friendly interfaces.


How to create a rest service using Open Rasta:

RestSharp A client only api for consuming rest services

RestSharp is a simple, open source REST client for .NET designed primarily for consuming third-party HTTP APIs. RestSharp is NOT:

  • A REST server framework
  • A SOAP client
Tagged , ,

SQL Server Express 2008 R2 – Installing on Windows 7 with Visual Studio 2010

Today I was trying to install the latest management tools for SQL Server using SQL Server Express 2008 R2 on a Windows 7 machine with Visual Studio 2010 running the setup up file I got the follow error message:

System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for userSettings/Microsoft.SqlServer.Configuration.LandingPage.Properties.Settings: Could not load file or assembly 'System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.

Solution: surprisingly easy just press Continue!


How to add custom validators to the SharePoint ListFieldIterator


Today I had the requirement to add custom validation logic to a SharePoint edit form. The edit form is being displayed using a ListFieldIterator. The requirement was to make sure the Date field could not be set to a date in the past.

The solution (Other solutions are available and are most probably better!) I came up with involved subclassing ListFieldIterator and attaching ASP.NET validators at run-time.

Challenge 1

How do you attach a ASP.NET validation control at run-time.

  • Attach the validator at the correct stage of the page/control life-cycle. In the case of the ListFieldIterator I wanted to attach it after the control had build it’s control tree. Override CreateChildControls, call base, then attach.
  • Find the FormField associated with the SharePoint field (SPField) you want to validate.I have an extension method that I use to parse the control hierarchy of a ListFieldIterator as follows:


FormField formField = listFieldIterator.GetFormField("MyInternalFieldName");

public static class ListFieldIteratorExtensions
    public static FormField GetFormField(this ListFieldIterator listFieldIterator, string fieldName)
        return GetFormField(listFieldIterator, GetFormFields(listFieldIterator), fieldName);

    public static FormField GetFormField(this ListFieldIterator listFieldIterator, List<FormField> formFields, string fieldName)
        FormField formField = (from form in formFields
                               where form.FieldName.Equals(fieldName, StringComparison.InvariantCultureIgnoreCase)
                               select form).FirstOrDefault();

        if (formField == null)
            throw new GeneralApplicationException("Could not find form field: " + fieldName);

        return formField;

    public static List<FormField> GetFormFields(this ListFieldIterator listFieldIterator)
        if (listFieldIterator == null)
            return null;

        return FindFieldFormControls(listFieldIterator);

    private static List<FormField> FindFieldFormControls(System.Web.UI.Control root)
        List<FormField> baseFieldControls = new List<FormField>();

        foreach (System.Web.UI.Control control in root.Controls)
            if (control is FormField && control.Visible)
                FormField formField = control as FormField;
                if (formField.Field.FieldValueType == typeof(DateTime))


        return baseFieldControls;

    private static void HandleDateField(FormField formField)
        if (formField.ControlMode == SPControlMode.Display)

        Control dateFieldControl = formField.Controls[0];
        if (dateFieldControl.Controls.Count > 0)
            DateTimeControl dateTimeControl = (DateTimeControl) dateFieldControl.Controls[0].Controls[1];
            TextBox dateTimeTextBox = dateTimeControl.Controls[0] as TextBox;
            if (dateTimeTextBox != null)
                if (!string.IsNullOrEmpty(dateTimeTextBox.Text))
                    formField.Value = DateTime.Parse(dateTimeTextBox.Text, CultureInfo.CurrentCulture);
  • Find the Control that is rendered by the FieldControl.Field.FieldRenderingControl. In my specific case a DateTimeField will render a DateTimeControl. Now that we have the form field we grab the rendering control:


Control renderedControl = GetControl(formField);

private static Control GetControl(FieldMetadata formField)
    return formField.FindControlRecursive(x => x.GetType() == GetChildControlBasedOnFieldType(formField.Field.FieldRenderingControl));

private static Type GetChildControlBasedOnFieldType(object field)
    if (field is TextField)
        return typeof(TextBox);

    if (field is DropDownChoiceField)
        return typeof(DropDownList);

    if (field is DateTimeField)
        return typeof (DateTimeControl);

    return null;

public static Control FindControlRecursive(this Control control, Func<Control, bool> evaluate)
    if (evaluate.Invoke(control))
        return control;

    foreach (Control childControl in control.Controls)
        Control foundControl = FindControlRecursive(childControl, evaluate);
        if (foundControl != null)
            return foundControl;

    return null;

  • Now we have found the control we want to validate, we can add the ASP.NET to it’s parent’s control collection

renderedControl.Parent.Controls.AddAfter(control, validator as Control);

Uses another little extension method:

public static void AddAfter(this ControlCollection collection, Control after, Control control)
    int indexFound = -1;
    int currentIndex = 0;
    foreach (Control controlToEvaluate in collection)
        if (controlToEvaluate == after)
            indexFound = currentIndex;

        currentIndex = currentIndex + 1;

    if (indexFound == -1)
        throw new ArgumentOutOfRangeException("control", "Control not found");

    collection.AddAt(indexFound + 1, control);

Tagged ,

How do you update the ‘Author’ or ‘Created by’ and ‘Editor’ or ‘Modified By / Last Modified’ fields of a list item (SPListItem)

Sometimes it’s useful to overwrite the created by and last modified by fields and get rid of that pesky ‘System Account’ !

Created By

The internal field name for the person who created a list item is ‘Author’ use SPBuiltInFieldId.Author to access this field. The display name for this field is ‘Created By’ it can be seen in the UI circled below:

SPListItem CreatedBy Author

Last modified

The internal field name for the person who created a list item is ‘Editor’ use SPBuiltInFieldId.Editor to access this field. The display name for this field is ‘Modified By’ it can be seen in the UI circled below:

SPListItem ModifiedBy Editor

Updating Created By, Modified By

The trick here is to call SPListItem.UpdateOverwriteVersion() instead of SPListItem.Update()

SPListItem item = list.Items[0];
item[SPBuiltInFieldId.Author] = "1;#Edward Wilde";
item[SPBuiltInFieldId.Editor] = "1;#Edward Wilde";
Tagged , ,

Typemock: System.NotSupportedException: Cannot dynamically create an instance of System.Void.

Had a problem mocking a call to SPWorkflowActivationProperties.Item today. Turns out to be a bug in the TypeMock library.

Problematic unit test

[Test, Isolated]
        public void PublishToExternalDocumentLibrary_Calls_CopyTo_Correctly()
            ApprovalWorkflow approvalWorkflow = Isolate.Fake.Instance<ApprovalWorkflow>(Members.CallOriginal, ConstructorWillBe.Called);
            SPWorkflowActivationProperties activationProperties = Isolate.Fake.Instance<SPWorkflowActivationProperties>(Members.CallOriginal, ConstructorWillBe.Called);
            SPListItem item = Isolate.Fake.Instance<SPListItem>();

            Isolate.WhenCalled(() => approvalWorkflow.PublishWhenComplete).WillReturn(true);
            Isolate.WhenCalled(() => approvalWorkflow.PublishDocumentLibraryUrl).WillReturn(ExternalDocumentLibraryUrl);
            Isolate.WhenCalled(() => approvalWorkflow.WorkflowActivationProperties).WillReturn(activationProperties);
            Isolate.WhenCalled(() => activationProperties.Item).WillReturn(item);
            Isolate.WhenCalled(() => item.Name).WillReturn("test.docx");
            // Fire the workflow completed event
            Isolate.Invoke.Event(() => approvalWorkflow.Completed += null, new object[] { this, EventArgs.Empty });

            Isolate.Verify.WasCalledWithExactArguments(() => item.CopyTo(""));

When executed it throws the following exception:

System.NotSupportedException: Cannot dynamically create an instance of System.Void.
at System.RuntimeType.CreateInstanceCheckThis()
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at hi.b(MethodBase A_0)
at hi.a(MethodBase A_0, fk A_1)
at a.a(fk A_0)
at a.c(fk A_0)
at fz.a(fk A_0)
at fz.a(Object A_0, MethodBase A_1, Object[] A_2)
at fz.a(Object A_0, String A_1, String A_2, MethodBase A_3, Object[] A_4, Object A_5)
at Microsoft.SharePoint.Security.SharePointPermissionAttribute.CreatePermission()
at System.Security.PermissionSet.CreateSerialized(Object[] attrs, Boolean serialize, Byte[]& nonCasBlob, PermissionSet& casPset, HostProtectionResource fullTrustOnlyResources)
at Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties.get_Item()
at Total.SharePoint.Approval.Workflow.Test.ApprovalWorkflowFixture.<>c__DisplayClassd.<PublishToExternalDocumentLibrary_Calls_CopyTo_Correctly>b__9() in ApprovalWorkflowFixture.cs: line 44
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
at Total.SharePoint.Approval.Workflow.Test.ApprovalWorkflowFixture.PublishToExternalDocumentLibrary_Calls_CopyTo_Correctly() in ApprovalWorkflowFixture.cs: line 0 

I can work around this issue by replacing the line:

Isolate.WhenCalled(() => activationProperties.Item).WillReturn(item);


Isolate.NonPublic.WhenCalled(activationProperties, "get_Item").WillReturn(item); 

See thread on Typemock forum

Tagged ,

InfoPath forms with workflow: ‘The form has been closed’ or Exception occurred during request processing. (User: {Domain}\{UserName}, Form Name: , IP: , Request: http://localhost/_layouts/CstWrkflIP.aspx?List={ID}, Form ID: , Type: InfoPathLocalizedException, Exception Message: The specified form cannot be found.)

Okay so today’s error message, totally my fault: was

Exception occurred during request processing. (User: DOMAIN\xx, Form Name: , IP: , Request: http://localhost/_layouts/CstWrkflIP.aspx?List={ID}, Form ID: , Type: InfoPathLocalizedException, Exception Message: The specified form cannot be found.)

Make sure that:

  • Your feature file has the RegisterFroms property correctly pointing to a folder in your solution package that contains your infopath forms

    WindowClipping (23)
    In my example all my info paths forms are contained in a sub directory called ‘Forms’ relative to feature file:
    WindowClipping (24)

  • Once the feature has been installed using stsadm –o install feature check that the forms have been placed in the InfoPath template library.

    Central Administration –> Application Management –> Manage Form Templates:

    WindowClipping (25)

As always, your mileage my vary. If this doesn’t help you could try some of the tips on Lucy’s blog:

Tagged ,

Toolbox –> "Choose items" crashes Visual Studio

If you ever encounter a crash when choosing the items to display in Visual Studios toolbox, then try this solution:


  • Start Visual Studio in safe mode using:  Start->Run->devenv /safemode
  • In the Toolbox “Choose items”, accept any error message the appear
  • Restart Visual Studio as per normal and the problem should be fixed.