Windows Phone Emulator wasn’t able to connect to the Windows Phone operating system

I encountered some problems while trying to start a Windows Phone Emulator from within Visual Studio 2012. In a WP8 project, after starting a debugging session, during the emulator loading, one of the following errors raised:

The Windows Phone Emulator wasn’t able to connect to the Windows Phone operating system:
The emulator couldn’t determine the host IP address, which is used to communicate with the guest virtual machine.
Some functionality may be disabled.

The Windows Phone Emulator wasn’t able to create the virtual machine: Something happened while creating a switch: Xde couldn’t find an IPv4 address for the host machine.

The WP8 app did not start, all I could see was the main tiled page of the emulated phone. Additionally, Visual Studio reported an error: “Invalid pointer“.

In order to solve this issue, follow this check list:

  1. Does your hardware support virtualization? Have you enabled it in BIOS?
  2. Are you running Windows 8 64-bit (x64) client version? It needs to be 64bit.
  3. Do you have any kind of other networking/virtualization software installed (VirtualBox, VPN software)? If you do, you might have to remove it to get the emulator work.
  4. Have you tried clearing the existing switches from Hyper-V manager and creating a new one? (run XdeCleanup.exe, is located in C:Program Files (x86)/Microsoft XDE/8.0)

Enjoy your work!

How to manage maps in Windows 8 without a native control

If you want to show a map with a pushpin in Metro app you need, up to now, to embed the Map into a WebView control to avoid the lack of a native Map Control in Windows 8.

To generate a valid URL from latitude and longitude parameters use this method in your code

public static string GetMapUri(double latitude, double longitude, int zoom, string mapStyle, int width, int height)
{
ObservableCollection pins = new ObservableCollection();

ImageryService.Pushpin pushpin = new ImageryService.Pushpin();
pushpin.Location = new ImageryService.Location();
pushpin.Location.Latitude = latitude;
pushpin.Location.Longitude = longitude;
pushpin.IconStyle = "2";

pins.Add(pushpin);

MapUriRequest mapUriRequest = new MapUriRequest();

// Set credentials using a valid Bing Maps Key
mapUriRequest.Credentials = new ImageryService.Credentials();
mapUriRequest.Credentials.ApplicationId = BingMapKey; // use your personal key

// Set the location of the requested image
mapUriRequest.Pushpins = pins;

// Set the map style and zoom level
MapUriOptions mapUriOptions = new MapUriOptions();

switch (mapStyle.ToUpper())
{
case "HYBRID":
mapUriOptions.Style = ImageryService.MapStyle.AerialWithLabels;
break;
case "ROAD":
mapUriOptions.Style = ImageryService.MapStyle.Road;
break;
case "AERIAL":
mapUriOptions.Style = ImageryService.MapStyle.Aerial;
break;
default:
mapUriOptions.Style = ImageryService.MapStyle.Road;
break;
}

mapUriOptions.ZoomLevel = zoom;

// Set the size of the requested image to match the size of the image control
mapUriOptions.ImageSize = new ImageryService.SizeOfint();
mapUriOptions.ImageSize.Height = height;
mapUriOptions.ImageSize.Width = width;

mapUriRequest.Options = mapUriOptions;

ImageryServiceClient imageryService = new ImageryServiceClient(ImageryServiceClient.EndpointConfiguration.BasicHttpBinding_IImageryService);
MapUriResponse mapUriResponse = null;
try
{
mapUriResponse = imageryService.GetMapUriAsync(mapUriRequest).Result;
}
catch (Exception ex)
{
Debug.WriteLine("GeoLocation: " + ex.Message);
}

return mapUriResponse.Uri;
}

You also need to reference the Bing Maps SOAP Services
GeocodeService
http://dev.virtualearth.net/webservices/v1/geocodeservice/geocodeservice.svc?wsdl

SearchService
http://dev.virtualearth.net/webservices/v1/searchservice/searchservice.svc?wsdl

ImageryService
http://dev.virtualearth.net/webservices/v1/imageryservice/imageryservice.svc?wsdl

RouteService
http://dev.virtualearth.net/webservices/v1/routeservice/routeservice.svc?wsdl

Wrap the generated string in a URI and insert it into the WebView controller.

How to locate resources in WinRT Metro App

MS invented another URI format for WinRT resources. For example, to set the Image.Source attribute on WinRT Metro App follow this steps:

  1. Define a new Image
  2. Add the Source attribute in the code behind
Image image = new Image();
image.Source = new BitmapImage(new Uri("ms-resource://MyAssembly/.../image.png", UriKind.ReletiveOrAbsolute));

You’ve to add the path above to locate the resouce in WinRT Metro App.