Exception no Azure Mobile Services com um PCL

Esses dias, estive trabalhando em um demo do Azure Mobile Services, para apresentar no trabalho.

Um dos objetivos deste projeto era a criação de um client Windows Phone 8.1, consumindo dados do Mobile Services. Para isso, criei uma app no AppStudio e gerei o projeto para editar no Visual Studio e fazê-lo pegar os dados da nuvem.

A solution gerada pelo AppStudio cria um projeto Portable Class Library (PCL) para manter o máximo possível de funcionalidades do client portável para outros projetos. Esse projeto que contém toda a conexão com o Mobile Services.

Ao implementar a API do Mobile Services e executar a app, estava sendo disparada, em tempo de execução, a seguinte exceção:

{System.InvalidOperationException: A Microsoft Azure Mobile Services assembly for the current platform was not found. Ensure that the current project references both Microsoft.WindowsAzure.Mobile and the following platform-specific assembly: Microsoft.WindowsAzure.Mobile.Ext.

Isso acontecia porque eu não tinha referenciado o Mobile Services no projeto de Windows Phone.

Embora o aplicativo do Windows Phone não use o Mobile Services diretamente (fica tudo no projeto PCL), você deve adicionar o pacote Windows Azure Mobile Services (via NuGet) para o projeto do client do Windows Phone, e assim garantir que as extensões específicas do client estejam incluídas na aplicação que será instalada no telefone.

Avoid Problems by Setting the App Theme in WP 8.1

You can define a default theme for your app, in WP 8.1.

In Windows Phone, there are two built in themes: “Light” and “Dark”. By default the system runs using the “Dark” theme. But the user can change this to use the “Light” theme.

So, whether your app has a completely custom UI, you might find some issues with components when the theme changes. Some text disappears and colours don’t contrast. To solve this, you can set the page’s RequestedTheme property to specify which theme is used.


You can use this property in the App.xaml file as well. This way your app will always use the settings (backgrounds, fonts, foregrounds, etc.) of the theme you’ve defined.

This also avoids the need to override properties and create styles in XAML.

Don’t forget to read the documentation for this at MSDN.

Configuring Git to use HTTPS Protocol

A few days ago, I was trying to clone the angular-seed git repository https://github.com/angular/angular-seed. Then I’d use bower to install realated libs with:

$ bower install

But, I was getting the following error, in gitbash:

Additional error details:
fatal: unable to connect to github.com:
github.com[0:]: errno=No such file or directory

After some research, and reading the logs, I’ve found that bower coudn’t execute some commands because Git was using url’s with git:// to fetch some repositories, and I was behind the firewall of the company I work.

To solve this, we need to configure Git to use HTTPS protocol instead the GIT transport, so bower can fetch dependencies:

$ git config --global url."https://".insteadOf git://

It’s weird, but it works.

After this, all url’s will use https:// to find the address. This is useful when you’re under a proxy in your company, or a firewall, for example.

How to get Device/User Info on Windows Phone 8

The Microsoft.Phone.Info namespace can be used to retrieve information about the device and the anonymous identifier information about the user. Unfortunately, some low-level properties are not available yet, such as IMEI or IMSI. But we can use other info to replace those.

First, put two text blocks at the .xaml to display info:

<TextBlock x:Name="DeviceProperties" Text="Device Id: " />
<TextBlock x:Name="UserProperties" Text="User ANID2: " />

Then you can use the following code to get the DeviceUniqueId, for example:

Byte[] DeviceUniqueId =
 (Byte[]) Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceUniqueId");
DeviceProperties.Text += Convert.ToBase64String(DeviceUniqueId);

And to display the user ANID2, for example, you can use:

UserProperties.Text +=

There are many properties available in this namespace, as you can see in the Microsoft.Phone.Info documentation

Using VirtualBox and Windows Phone SDK on same Windows

A few days ago, I needed to install VirtualBox to mount my Linux VM’s. Everything worked perfectly, and with 64bit available. Some time later, I had to install the Windows Phone SDK 8, to create a prototype app. It also worked correctly.

But, when I needed to start a VM again, I received the following error:

VirtualBox Import Appliance; VT-X is not available.

Doing a research, I figured that this means that virtualization is not available on the computer, or in the operating system. When checking in the BIOS, virtualization was enabled – since it worked before.

So the problem could be in Windows 8 (which is the host).

The Windows Phone SDK uses Hyper-V

To install and use the Windows Phone 8 SDK,  Hyper-V is required, and it is where it can run the phone emulator.

So the SDK intalls Hyper-V and activates it. Hyper-V starts executing when the computer reboot. (By the way, Hyper-V is extremely heavy for common use, make direct debug the device itself.)

After a boot or reboot, Hyper-V will “take over” of all features on Windows.

When you enable Hyper-V, Windows becomes an virtualized environment and VirtualBox no longer have direct access to hardware. This is normal. Your Windows starts to behave as a virtual machine. And with that, the VirtualBox VM’s stop working.

It’s like trying to open a VM inside another VM. Which is not possible.

Disable Hyper-V and Reboot

To solve this problem, you must completely disable the Hyper-V on Windows:

  1. Open the Control Panel;
  2. Go to Enable or Disable Windows Features;
  3. Uncheck Hyper-V and OK;
  4. Restart the PC

You really need to reboot, so the virtualization layer (Hyper-V) can be disabled in the operating system. Most likely, the emulator Windows Phone 8 will stop working.

I recommend that you use a real device to debug and have a more real feeling of your app.

See Also…