0 Comments

As the PC makers seem to have some problems getting the Haswell based ultrabooks to market, I decided to get MacBook Air 2013 (MBA 13 i5 model) and use it as my main development machine with the help of Boot Camp. UnfortunatelyI encountered a deal breaker:  I couldn’t turn on Hyper-V in Windows 8:

Hyper-V cannot be installed: Virtualization support is disabled in the firmware

Hyper-V is required when one wants to do Windows Phone 8 development, which I do quite much.

But fortunately, there’s a fix for this, though it has couple problems:

  1. It costs money
  2. The solution is just bizarre

In order to enable Hyper-V you have to follow these steps:

  1. Boot the computer into Mac OS X
  2. Purchase (or get the trial), download and install Parallel Desktop for Mac
  3. Reboot back to Windows 8

And that’s it, the Hyper-V is now available.

image

If you turn off the computer at some point, the Hyper-V gets disabled until you boot into Mac OS X and run the Parallel Desktop again. So it’s better just to put the MacBook to sleep.

Bizarre, isn’t it?

I suppose this is just a bug in the firmware as MBA 12 seems to support the Hyper-V just fine. But, until the bug is fixed, this works as a workaround. Thanks to TigerG for posting his findings at MacRUmors.

1 Comments

I had a simple Portable Class Library project which used Microsoft HTTP Client Libraries (System.Net.Http.HttpClient). The problem: The Visual Studio wouldn’t compile it:

The type or namespace name ''Http'' does not exist in the namespace ''System.Net'' (are you missing an assembly reference?)

The PCL project targeted the following frameworks:

  • Windows Phone 8
  • Silverlight 5
  • .NET 4.5
  • Windows Store apps

I was using the stable 2.1.10 release of the HttpClient library. Resharper didn’t find anything wrong with the code but still it wouldn’t compile. So I created an another PCL project, added the same HttpClient NuGet package and the same code. And it compiled without a problem.

So I had two identical projects with identical references and with identical code. But only one of them compiled.

I decided to diff the project files and this helped me to notice that the non-compiling project had an app.config –file:

image

And the configuration contained bindingRedirects:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

When I created the non-compiling PCL project, I set some of the target frameworks wrong. Because of this, it seems, the HttpClient Nuget-package added the configuration. And this broke the compilation after I had fixed the target frameworks.

The solution was simple: I just had to remove the runtime-element from the configuration.

2 Comments

Twitter Bootstrap broken in Windows Phone, Wensus image

Unfortunately the latest Twitter Bootstrap is broken with Windows Phone: The responsive layout doesn't work.

We noticed this when updating the Wensus website. This is how the site worked with a version 2.2.1 (captured from Windows Phone emulator):

And this is what happened after we upgraded to latest Twitter Bootstrap version (2.3.1):

Rolling back to 2.2.1 fixed the issue.

There's a short discussion about this on GitHub dating back to last December. The issue has been closed as the Bootstrap team doesn't officially support Windows Phone. Which is really unfortunate.

Here's a short tutorial on how to make Durandal, PhoneGap and Windows Phone 8 work together:

Download and install PhoneGap’s Visual Studio 2012 template

Start by downloading PhoneGap. At the time of writing this, the latest version is 2.7.0. From inside the zip, copy CordovaWP8_2_7_0.zip(in folder lib/windows-phone-8)to Documents/Visual Studio 2012/Templates/ProjectTemplates:

image

Create a new Windows Phone 8 app using the template

Next step is to create the actual Windows Phone 8 app. For that, use the new Cordova-template:

image

Clone the Durandal and add it to the app

Next step is to get Durandal. After cloning the project, copy App, Content and Scriptsfolders into the app’s www-folder:

image

Now we just need to modify the PhoneGap’s Index.html so that it uses Durandal.

Create the Index.html for Durandal

Open the index.html and replace the content with this:

<!DOCTYPE html>
<html>
<head>
    <title>Durandal</title>

    <link rel="apple-touch-startup-image" href="Content/images/ios-startup-image-landscape.png" media="(orientation:landscape)" />
    <link rel="apple-touch-startup-image" href="Content/images/ios-startup-image-portrait.png" media="(orientation:portrait)" />
    <link rel="apple-touch-icon" href="Content/images/icon.png" />

    <!--Durandal does not require Bootstrap or Font Awesome. 
            They are used to make the samples look nice.-->
    <link rel="stylesheet" href="Content/bootstrap.min.css" type="text/css" />
    <link rel="stylesheet" href="Content/bootstrap-responsive.min.css" type="text/css" />
    <link rel="stylesheet" href="Content/font-awesome.min.css" type="text/css" />

    <!--The css in this file makes the modal dialogs work right.-->
    <link rel="stylesheet" href="Content/durandal.css" type="text/css" />

    <!--Css specific to the samples.-->
    <link rel="stylesheet" href="Content/app.css" type="text/css" />

    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />

    <meta name="viewport" content="width=device-width" />
    <script type="text/javascript" src="cordova-2.7.0.js"></script>
</head>
<body>
    <div id="applicationHost"></div>

    <script type="text/javascript" src="Scripts/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="Scripts/knockout-2.2.1.js"></script>
    <script type="text/javascript" src="Scripts/sammy-0.7.4.js"></script>
    <script type="text/javascript" src="app/durandal/amd/require.js" data-main="app/main"></script>
</body>
</html>

In theory, that should be it. But if you run the app, you’ll notice that everything is not working correctly:

image

The source of problem can be found from Visual Studio’s output window:

image

So it cannot find the shell.html, even though it’s where it should be:

image

“Fix” the PhoneGap

The PhoneGap Visual Studio 2012 template includes the PhoneGap’s source code, which is great. If you now open the Plugins/File.cs and set a breakpoint to readResourceAsText-method, you’ll see what’s causing the problem:

image

PhoneGap tries to read the file from a wrong folder!The folder is missing the www-part.

Now make a little tweak to the code:

                pathToResource = "www/" + pathToResource;
                var resource = Application.GetResourceStream(new Uri(pathToResource, UriKind.Relative));

And then run the app again and here it is! Durandal running in a PhoneGap based Windows Phone app:

image

Source Code

I created a repository for this sample on GitHub. It’s available from here.

3 Comments
  •   Posted in: 
  • UWP

Using Basic Authentication in a WinRT app is a common requirement. The basic authentication isn’t supported out-of-the box by the HttpClient  but the HttpClient class has a good extensibility model: The basic authentication can be implemented using a custom DelegatingHandler:

    public class BasicAuthHandler : DelegatingHandler
    {
        private readonly string username;
        private readonly string password;

        public BasicAuthHandler(string username, string password)
            : this(username, password, new HttpClientHandler())
        {
        }

        public BasicAuthHandler(string username, string password, HttpMessageHandler innerHandler)
            : base(innerHandler)
        {
            this.username = username;
            this.password = password;
        }

        protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            request.Headers.Authorization = CreateBasicHeader();

            var response = await base.SendAsync(request, cancellationToken);

            return response;
        }

        public AuthenticationHeaderValue CreateBasicHeader()
        {
            var byteArray = System.Text.Encoding.UTF8.GetBytes(username + ":" + password);
            var base64String = Convert.ToBase64String(byteArray);
            return new AuthenticationHeaderValue("Basic", base64String);
        }
    }

The BasicAuthHandler can be used by passing it into the HttpClient’s constructor:

            var client = new HttpClient(new BasicAuthHandler("username", "password"));

            var data = await client.GetStringAsync("http://secured.address.com/api");