• ASP.NET Web API for .NET Framework 4 in Visual Studio 2015

    This is a pretty unique set of constraints I know – sometimes there are limitations outside your control as to which version of .NET you (or those who will be running your software) can use.

    Note that the most recent version of Web API that works with .NET Framework 4.0 is 4.0.30506.0 (The 5.x releases all require at least .NET 4.5)

    1. Open Visual Studio 2015
    2. Create a new project (Make sure you select .NET Framework 4 in the frameworks dropdown list) Visual Studio New Project dialog
    3. Open the Package Manger Console
    4. Enter Install-Package -Id Microsoft.AspNet.WebApi -Version 4.0.30506 -DependencyVersion HighestMinor
    5. Update-Package Newtonsoft.Json
    6. (Optional) Install-Package -Id Microsoft.AspNet.WebApi.Tracing -Version 4.0.30506
    7. Add an App_Start folder
    8. Inside this folder, add new class WebApiConfig
    9. Add the following content to the WebApiConfig class:
    public static void Register(HttpConfiguration config)
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new
                id = RouteParameter.Optional
        // Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type.
        // To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries.
        // For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712.
        // To disable tracing in your application, please comment out or remove the following line of code
        // For more information, refer to: http://www.asp.net/web-api
    1. In the top-level of the project, add a Global.asax file
    2. Open the Global.asax.cs file and add the following method:
    protected void Application_Start()
    1. Add a Controllers folder
    2. Inside the Controllers folder, add a new class (eg. ValuesController)
    3. Update the ValuesController class to look as follows:
    public class ValuesController : ApiController
        // GET api/values
        public IEnumerable<string> Get()
            return new string[] { "value1", "value2" };
        // GET api/values/5
        public string Get(int id)
            return "value";
        // POST api/values
        public void Post([FromBody]string value)
        // PUT api/values/5
        public void Put(int id, [FromBody]string value)
        // DELETE api/values/5
        public void Delete(int id)

    Your project should look similar to this:

    Solution Explorer showing Web API project

    You can now build and run the web application and browse to /api/Values and get a response from your controller (JSON or XML depending on your browser)

  • Solution to error 0x80240020: Upgrade to Windows 10

    So the whole “[delete the contents of the downloads directory]/2015/07/installation-failure-windows-failed-to.html)” thing didn’t work for me.

    Today I noticed a tweet linking to an article, which in turn referred to a post in the Microsoft forums.

    Apparently, the error 0x80240020 is not an indication of any download corruption – just that you’re computer is in a “holding pattern” waiting for the green light from Microsoft, as they’re staging the upgrade process. I think it would have been preferable to have just had this sitting quietly on my computer, rather than littering my Update History with “Update failed” messages.

    So if you don’t want to wait, there’s a registry key you can set. (Instructions for setting registry key repeated here from the forum post)

    1. Locate the registry key: [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\OSUpgrade]

    2. It should exist, but if not, create it.

    3. Create a new DWORD (32-bit) Value with Name = “AllowOSUpgrade” (without the quotes), and set the Value = 0x00000001.

    Now go back to the Windows Update in Control Panel, and tada – a new screen appears!

    Windows Update in Control Panel, prompting to Get started

    Click on the Get started button and things start happening..

    It thinks for a short time, then the Windows Update prompt appears on your desktop:

    Dialog prompting to start the upgrade now

    And back in the Control Panel, you’re also prompted to restart. Clicking Start the upgrade now, or Restart now both do the same thing

    Windows Update in Control Panel, prompting to restart

    Your computer reboots, and the upgrade proceeds.

    After a little while, and a few reboots later, you now have Windows 10!

    About Windows 10 dialog


  • Installation Failure: Windows failed to install the following update with error 0x80240020: Upgrade to Windows 10 Pro.

    Update – Note that this didn’t work for me. Still waiting to find a workaround, otherwise I’ll try using an ISO instead

    Eagerly waiting for Windows 10 to upgrade my PC.. But nothing was happening. I noticed this error in the Event Viewer System Log:

    “Installation Failure: Windows failed to install the following update with error 0x80240020: Upgrade to Windows 10 Pro.”

    This thread suggests the cause may be a corrupt download.

    The solution (repeated here):

    1. Delete the contents of C:\Windows\SoftwareDistribution\Download
    2. Open an elevated Command Prompt and run wuauclt /updatenow
    3. Go to Control Panel Windows Update and click Check for updates.

    After a minute or two, you’ll notice some new files appear in the Download folder, and the Windows Update status will change similar to this:

    Downloading Windows 10

    I’ll update this post if there’s anything else that requires attention to complete the upgrade successfully.

    Later that same day…

    Windows Update - Preparing for installation

    and even later…

    The installation failed with the same error 😢