Windows 8 RTM is here: how to fix activation issues and submit apps to the store!

Since yesterday, as previously announced, Windows 8 and Visual Studio 2012 RTM are available to MSDN and TechNet subscribers. Even if this is an important news, since it marks a new milestone for Microsoft, there isn’t too much to tell: thanks to the preview version released during this year we are already familiar with the new Microsoft OS and with the new way to develop applications using the new WinRT runtime.

In this post I would like just to highlight two important information: how to fix activation issues and how to start submitting apps to the store even if you don’t have a MSDN subscription.

Activation issues

Many people (me included) have experienced issues while trying to activate their Windows 8 copy, by getting the error DNS name does not exist. This problem occurs usually with the Enterprise edition, since it requires a multi activation key. There’s a workaround for this:

  1. Open a command prompt with admin privileges.
  2. Type slmgr /ipk followed by the product key you’ve obtained from MSDN (for example, slmgr /ipk xxxxx-xxxxx-xxxxx-xxxxx-xxxxx).
  3. Start the activation process.

This time everything should work fine and you’ll be able to enjoy all the Windows 8 features.

Submit apps to the store

Now that the RTM is released developers will be able to submit apps to the store: the problem is that, obviously, you are required to compile and test your app against the RTM release but, if you don’t have a MSDN or TechNet subscription, you won’t be able to get a Windows 8 copy until 26th October.

To allow developers without a subscription to submit their apps anyway Microsoft has released an evaluation version, that will expire in 90 days after the installation. It’s a full Windows 8 version, so you can use for development purposes without any glitch.

The only downside is that the evaluation version can’t be updated to a full version after 26th October: you will need to install everything from scratch. For this reason, I suggest you to install it in a virtual machine or in a dedicated partition and not to use it as your main operating system. You can download the evaluation version from here.

Have fun with Windows 8!

Posted in Windows 8 | Tagged | Leave a comment

Import an already existing SQLite database in a Windows 8 application

One of the comments I’ve received in the blog post I wrote about using SQLite in a Windows 8 application was a really interesting question: what can I do if I have a pre populated SQLite database and I want to use it in my application? In fact, the blog post I wrote was based on a “code first” approach: according to some classes attributes, the database was generated during the first execution of the application.

The solution is pretty simple, thanks to the WinRTs APIs used to interact with the storage. If you recall the explanation in my previous post, you’ll know that sqlite-net (the library used to interact with the SQLite database using a LINQ syntax) looks for the database file inside the local folder of the application. What we’re going to do is to include our database file into the project and then, when the application is launched for the first time, copy it into the local storage, so that the library can access to it.

The first step is to copy your database in to the Visual Studio project and, from the Properties window, set the Build action to Content.

Once you’ve done this operation, you’ll be able to access to the files embedded in your project thanks to the Package.Current.InstalledLocation object that is available in the Windows.ApplicationModel namespace.

The InstalledLocation’s type is StorageFolder, which is the base class of all the folders mapping in WinRT: for this reason, it exposes all the standard methods to interact with the storage, like getting a file or a folder. This way we can use the GetFileAsync method to get a reference to the database embedded into the project and, after that, using the CopyAsync method we can copy it into the local storage of the application. We can copy it in the root of the local storage (like in the following example) or in a specific folder, by getting a reference to it first using the GetFolderAsync method.

Here is a sample code:

private async Task CopyDatabase()
{
    bool isDatabaseExisting = false;

    try
    {
        StorageFile storageFile = await ApplicationData.Current.LocalFolder.GetFileAsync("people.db");
        isDatabaseExisting = true;
    }
    catch
    {
        isDatabaseExisting = false;
    }

    if (!isDatabaseExisting)
    {
        StorageFile databaseFile = await Package.Current.InstalledLocation.GetFileAsync("people.db");
        await databaseFile.CopyAsync(ApplicationData.Current.LocalFolder);
    }
}

 

The code should be simple to understand: the first thing we do is to check if the file already exists or not. If it doesn’t exist, we get a reference to the file embedded in the Visual Studio project (called people.db) and then we copy it in the local storage (that is mapped with the object ApplicationData.Current.LocalFolder). This way the file is copied in the root of the local storage.

After that, we can use the same code we’ve seen in the first post to access to the database and perform queries: it’s important to remember that the name of the classes that identify the database tables should have the same name of the tables in the database we’ve imported.

Posted in Windows 8 | Tagged , | 50 Comments

Welcome to Windows Phone Dev Center!

image

Two days ago Microsoft has shutted down AppHub for maintainance and, after a few hours, reopened it with many surprises. The first is that AppHub doesn’t exist anymore and it’s been replaced by a new portal called Windows Phone Dev Center. AppHub was a unique portal to submit both Windows Phone application and XBox 360 indie games with a unique subscription: now the two portals have been split and the Windows Phone Dev Center is available at the URL https://dev.windowsphone.com/

But this is just the first of many news: the second thing you’ll notice immediately is that the portal features a brand new UI, that is more clear and, especially, faster and that doesn’t require anymore external plugins (now everything is just pure HTML, the previous submit process was developed with Silverlight). What you won’t notice but you will surely appreciate is that the entire backend of the portal has been rewritten from scratch, in order to fix all the bugs and problems that developer has experienced in the latest months.

But let’s see in details which are the new major features.

Payment improvements

The most important new features are related to the payment process: the first one is that now Paypal is accepted, both to pay subscription and to receive payments from Microsoft for apps selling.

The second great news is related to tax profile: if you live outside the United States the procedure to get paid by Microsoft was really tricky. In fact, in order not to be taxed twice (both from United States and from your country) developers have to fill a module called W8 and to send it: the procedure was really complicated, since it required to fill a lot of papers and send them by regular mail to a United States mailbox.

Now the procedure is extremely simple: a wizard will guide you filling all the required fields and the W8 module will be automatically sent at the end of the process. No more paper, no more regular mail, no more complex procedures. Awesome!

Important! If you’ve previously completed the tax profile with the regular procedure, you may not see it in the new portal: Microsoft is still migrating the old tax profiles, so you should see it in a couple of days. If you don’t want to wait (because, for example, you need to submit an application) you can simply send a new W8 module using the new wizard.

Another nice new feature is that now you’ll be able to set different prices for different market: previously, developers were able just to set one price, that was automatically converted to every country currency.

Last but not the least, the new portal now supports in-app purchase management: actually, you still can’t use it since it will be a new Windows Phone 8 feature, but the architecture is already in place for the future.

New reports

The report section of the portal has been improved with some new features: the first is a new filter, that allows you to see graph and statistics filtered not only by country and application, but also by type (paid, trial, free).

Plus, all the money reports have been grouped into a new section called My money.

Some new options to distribute your apps

You’ll immediately notice that the submit process has been totally changed: the interface is very different and also the required steps are in a different order. One thing you’ll notice is that the concept of private marketplace is gone: this way to distribute apps is still there, but it has a different name. Now  you simply have an option called Hide from users browsing or searching the Store that you can enable when you choose to publish your app in the public store.

The second new feature is that now you can distribute your beta apps up to 10.000 testers (previously, the limit was set to 100).

In the end, Microsoft has added a new interesting option, especially now that the Marketplace has been opened to many countries: you can automatically choose to exclude from the distribution all the countries that have more restrictive policies about content. Previously, you were just able to pick one country at a time or simply to choose all the available countries.

What do you think?

The first impression with the new Windows Phone Dev Center is really good: AppHub was probably the weakest point in all the Windows Phone ecosystem; the submit process was tricky and the bugs and issues were really frustrating. Now everything is smooth, fast and fluid: and this is just the beginning, Microsoft has promised more improvements in the next months.

Before closing, I want to highlight a good news for all the owners of a MSDN subscription: soon you will get a free one year subscription to the Windows Phone Marketplace included in your subscription, just like it’s been recently announced and enabled for the Windows 8 Store.

If you want, you can read the full announcement about the Windows Phone Dev Center on the official blog of the team.

Posted in Windows Phone | Tagged | Leave a comment

How to deal with the “Unspecified error” in a Windows Phone application

While developing and testing a Windows Phone application you may have to deal with a really annoying problem: your application crashes and the only error reported by Visual Studio is a generic Unspecified error.

Visual Studio itself isn’t of any help, because the error is intercepted by the global error handler available in the App.xaml.cs file, so you don’t have a way to understand where exactly the problem occured.

The solution is easy to understand, even if it’s not easy to find: this error is raised usually when your XAML contains a property with an invalid value. For example, when I had to deal with this error I found that, by mistake, the Margin property of a control contained the value 0k, 0, 0, 15, that is obviously not correct (the margin property accepts only numeric values).

To help understanding where your application may contain such an error, keep track of the the time when Visual Studio intercept the “Unspecified error” exception: usually, this error is raised only when you navigate towards a page that has this problem.

Good debugging!

Posted in Windows Phone | Tagged | 1 Comment

How to display GIF images in a Windows Phone application

Some time ago I was talking with a friend that needed a special requirement for his application: displaying GIF images downloaded from the web. This image format is not supported by Silverlight nor Windows Phone: if you try to download and display a GIF image inside an Image control you’ll get an exception.

So I searched a little bit on the Internet to find a possible solution and I came out with ImageTools, a third party library that contains many converters and tools to convert one image from a format to another on the fly. One of the supported scenario is GIF images conversion (that can be animated, too) for Windows Phone.

Let’s see how to use it: the first thing is to add the library to your project and, as usual, the easiest way to do is with NuGet.

To use this library to achieve our goal we need to use two components:

  • The first is a control called AnimatedImage, which is going to replace the standard Silverlight Imagecontrol. It’s the container that will display the image.
  • The second is a converter called ImageConverter, which takes care of converting the image from one format to another.

Both objects are part of the ImageTools.Controls namespace, that should be declared in the XAML page where we’re going to use them.

xmlns:imagetools=”clr-namespace:ImageTools.Controls;assembly=ImageTools.Controls”

Once you have imported the namespace, you can add the converter as a resource for the page or, if you prefer, for the global application. Here is an example on how to do it for a single page:

<phone:PhoneApplicationPage.Resources>
    <imagetools:ImageConverter x:Key="ImageConverter" />
</phone:PhoneApplicationPage.Resources>

If you want to make this resource globally available, you just have to declare it inside the Application.Resources section inside the App.xaml file.

Now you are ready to insert the AnimatedImage control into your page: you simply have to bind the Source property with a Uri object (which contains the URL of the gif image) and apply the Image converter.

Here is an example of the XAML declaration:

<StackPanel>
    <imagetools:AnimatedImage x:Name="Image" Source="{Binding Path=ImageSource, Converter={StaticResource ImageConverter}}" />
</StackPanel>

And here, instead, is how the ImageSource property is defined in the code:

ImageSource = new Uri("http://www.nonstopgifs.com/animated-gifs/games/games-animated-gif-002.gif", UriKind.Absolute);

We’re almost done: the trick to make the “magic” working is to use one of the decoders that are available in the ImageTools library: these decoders take care of the conversion process and they should be initialized when the application or the page is created, specifying which is the image format to use.  We are using this library for GIF conversion, so here is how to register the GIF decoder.

public MainPage()
{
    InitializeComponent();
    ImageTools.IO.Decoders.AddDecoder<GifDecoder>();
}

As I anticipated in the beginning of this post, this control supports animated GIFs too: if you try the example GIF used in this post you can see it by yourself.

Posted in Windows Phone | Tagged | 14 Comments