If you have encounters an SQLCeException error during a LINQ operation for example Union on a very large data set, check the error message. If the error message shows something like “The database file is larger than the configured maximum database size. This setting takes effect on the first concurrent database connection only.“, then congratulation to you, because you just hit the limit.

The Windows Phone team think any application in phone should not use that much memory, but still some of us might hit this limit. For example like me which required to search through 20,000+ data sets with complicated search conditions. The solution to this problem is pretty simple, add a max database size in the connection string to SQL CE. You will need a complete connection string this time instead of just defind the location of your SQL CE database file.

For example, my connection string before this is as follow:

@"isostore:/CardsDatabase.sdf"

Then after adding the max database size parameter and convert it to a complete connection string, it will become like this:

@"Data Source='isostore:/CardsDatabase.sdf';Max Database Size=64;"

The 64 in the connection string mean I wants to increase the max database size to 64 MB instead of the default value. Hope this little information can help.

by Ooi Keng Siang via Ooiks’s Blog

With the release of Windows Phone SDK 7.1.1 Update, building Windows Phone 7 app on Windows 8 is now possible. I decided to jump on and try out Windows 8 while building my Windows Phone app, but I hit the wall right after I install Windows 8, Visual Studio and all the SDK then compile my Windows Phone app. Visual Studio told me that Microsoft.Xna.Framework.dll (which is use to play sound in my Silverlight app) is not found.

Aren’t the new 7.1.1 update suppose to make everything all right? It turn out that there are some problems with XNA which didn’t get installed when I run Windows Phone SDK 7.1. After some searching on the net and I found the solution for this. Just simple follow the following step by step:

  1. Download and install Zune Software (if you haven’t install)
  2. Download and install Games for Windows Marketplace Client
  3. Download and install Windows Phone SDK 7.1
  4. Download and install Windows Phone SDK 7.1.1 Update

Oh, just in case you installed everything but without the  Games for Windows Marketplace Client, you will need to repeat the step 2 to 4 (if you haven’t install Zune, then you need to repeat step 1 to 4).

Although everything work perfectly OK, but the emulator is a little bit lag compare running on Windows 7 which was a known issue in Windows 8.

 

Source

 

by Ooi Keng Siang via Ooiks’s Blog

Last few days, I was trying to develop a new project that involve saving some Contact data from phone to isolated storage or IsolatedStorageSettings. The reason behind this , I want the app to keep track of a list of favorite contacts. Everything went smooth until the part saving the contacts into isolated storage. It was a nightmare. Saving a copy of contact data into isolated storage did not give me any warning or problem at all. However after I quit the app and restart, the app fail to retrieve any contact data from isolated storage. It look like the app never successful save any data to the isolated storage.

 

public List<FavoriteContact> LoadFavoriteContactsFromStorage()
{
    try
    {
        if (IsolatedStorageSettings.ApplicationSettings.Contains("FavoriteContacts"))
        {
            List<FavoriteContact> tempFavoriteContacts;
            if (IsolatedStorageSettings.ApplicationSettings.TryGetValue<List<FavoriteContact>>("FavoriteContacts", out tempFavoriteContacts))
            {
                return (tempFavoriteContacts);
            }
        }
    }
    catch
    {

    }

    return (new List<FavoriteContact>());
}

public void SaveFavoriteContactsToStorage()
{
    IsolatedStorageSettings.ApplicationSettings.Remove("FavoriteContacts");
    IsolatedStorageSettings.ApplicationSettings.Add("FavoriteContacts", FavoriteContacts);
    IsolatedStorageSettings.ApplicationSettings.Save();
}

 

At first, I though I did something wrong in load or save function related with isolated storage. After debugging the whole day, it turn out that the function work perfectly OK without any problem. It did not throw me a single error at all. After Bing here and there on the Internet, at last I found culprit of this problem. It is the Contact data itself. In the Best Practices for Contact class, I found the following message:

Contact data is provided as a read-only snapshot. If your application needs fresh data, repeat the original search periodically.

Although the app did not throw any error, warning or exception, but I think it is not possible to direct save the Contact object into the isolated storage. Why I think instead of I’m very sure? This is because I can’t find any information related witht the same problem I’m facing, so I assume read-only Contact object can’t be saved. I replace the Contact class with another class I build with the similar properties with Contact class, then everything work nicely.

The conclusion here is you can’t save Contact object to isolated storage or IsolatedStorageSettings . No error, warning or exception if you do that, but it just don’t work and it will screw your whole day by letting you figure out what happen actually.

by Ooi Keng Siang via Ooiks’s Blog

Displaying advertisement in free app to generate some extra revenue is a very common approach use by many developers in many different platform. If you are living in the country where  Microsoft Advertising pubCenter is supported, then good for you because you will have a much easier life. But if you are not, or would like to show not only ad from Microsoft provider, then this post if for you.

I had personally tried Google AdMob and Smaato ad provider for Windows Phone before. They don’t work out nicely for me. Google AdMob SDK crash randomly when request ad from server (post). While Smatoo didn’t show any ad in the app some time when use in my home country (post). Microsoft Advertising pubCenter  is not an option for me since it is not available in Malaysia.

Then I come across Windows Phone 7 Ad Rotator, which can show ads from different providers. It support both Google AdMob and Smaato, so I decided to give it a try. End up it work perfectly in my app. The Ad Rotator solve the crash problem in Google AdMob native SDK (now I can use back AdMob) and it also help to display ad from different providers when the other provider fail to show any ad. For example, I set both Smaato and AdMob in Ad Rotator, when AdMob fail to show any ad,  Smaato will take over and show the ad instead. This help to maximize the revenue of your free app in many different countries.

Currently Ad Rotator is in version 1.0 which support Microsoft PubCenter, AdDuplex, Google AdMob, Inner-Active, MobFox, Smaato and Default House Ad. It also support both Silverlight and XNA app in Windows Phone. You can find a very easy tutorial here. It is very easy to integrate in your Windows Phone app. I will recommend any developer who want to show advertisement on their free app to give this a try.

I had now switch to Ad Rotator to display ads from Smaato and AdMob. Mainly because it can switch between different providers. When one failed to show, the others will take over. Second, I can add more ad providers later on without making any changes in my source code. Although I can further maximize the revenue by using different ad providers in different countries (eCPM will depend on the ad display, country and ad provider), but I don’t have any idea which ad provider give better pay on which country yet, so I will stick with 50-50 for Smaato and AdMob currently.

by Ooi Keng Siang via Ooiks’s Blog

I’m don’t really understand why compress or zip function was not added to Silverlight or Windows Phone since the Silverlight package or Windows Phones xap file was actually a zip file. Windows Phone will need to unzip all file download from marketplace in order to install in the phone. While I’m looking for a third party library to unzip file in my Windows Phone app, I come across this REALLY small unzip utility for Silverlight, which re-use the existing functions in Silverlight to done the job. Great, this is just what I looking for and the best part of it, the size is really small. It is just a C Sharp file!

A very simple tutorial for REALLY small unzip utility for Silverlight was provided on his blog but I found a missing function in the code. The GetFileNamesInZip can’t be found by Visual Studio. After taking a quick look in the source file, I found out that the function name was changed to FileNamesInZip instead. Below are the same example but with corrected function name call instead.

private void LoadZipfile()
{
    WebClient c = new WebClient();
    c.OpenReadCompleted += new OpenReadCompletedEventHandler(openReadCompleted);
    c.OpenReadAsync(new Uri("http://www.mydomain.com/myZipFile.zip"));
}

private void openReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
    UnZipper unzip = new UnZipper(e.Result);
    foreach (string filename in unzip.FileNamesInZip())
    {
        Stream stream = unzip.GetFileStream(filename);
        StreamReader reader = new StreamReader(stream);
        string contents = reader.ReadToEnd();
        MessageBox.Show(contents);
    }
}



Download REALLY small unzip utility for Silverlight  

by Ooi Keng Siang via Ooiks’s Blog

 

MTGBugs is a comprehensive app or tool for Magic the Gathering player. It integrate all kind of different tools which required by Magic players in one single app. For example life counter, dice roll, offline cards database, online card pricing, deck builder analysis, latest news update and many more. MTGBugs currently is the only app in Windows Phone marketplace with the most complete features builds into it.

MTGBugs main features include:

  • Game tracker include life and poison counter, game timer, mana pool counter, random dices
  • Commander format support up to 12 players with commander cast counter and achievements check list
  • Offline cards database with 20,000+ cards collection and online card pricing integrated (All prices courtesy of TCGPlayer.com)
  • Decks builder with up to date winning deck lists and automatic analysis tool build in
  • Wishlist and direct purchase through online shop from TCGPlayer.com
  • Online news direct from Daily MTG, StarCityGames, ChannelFireball and TCGPlayers
  • Photo capture and sketching tool to record opponent hand’s cards

More »

You may have notice Malaysia country is now listed in Windows Phone website. If you go to the marketplace, you can now search app that is available in Malaysia marketplace. This mean that the Windows Phone marketplace is ready for Malaysia consumers. Malaysia developers hold your horse, app submission to App Hub directly is not ready yet and you will still need to go through third party currently, check out my previous post.

The very first thing that piss me off is I can’t change the language to English if I selected Malaysia as the country in the website. Malay language was the only language provided. Why? Running translation in my head full speed while browsing the site is killing my brain cell. Fix this please! OK! enough, back to the topic.

You may found there are lot fewer apps in Malaysia marketplace compare with US marketplace. This is because many apps was submitted before Malaysia marketplace is ready for distribution. This mean that unless developers of those missing apps resubmit their app and select distribution to Malaysia, else it won’t be available to Malaysia marketplace. This doesn’t sound bad at all, because usually app that no longer updated are some useless app, so this can pretty much filter a lot of useless apps in Malaysia marketplace.

As for now Malaysia developers still need to submit their apps through third party like Yalla Apps in order to publish their apps to Malaysia marketplace and other country marketplace. Some developers still refuse go into Windows Phone development because they worry what will happen to their apps once the marketplace is fully open for developers in Malaysia and they can submit their app direct through App Hub. From what Microsoft and Yalla App done previously, developers can transfer their app to App Hub when it is fully open. Check out this post. So this is the best time to jump into Windows Phone development.

The news has been confirmed at Windows Phone Blog.

I’m still waiting for one of my fully developed app to get through the app submission and my new Windows Phone to ship to my hand. Such a long wait before I can play the fun out of it.

By Ooi Keng Siang via Ooiks’s Blog

Ever since Windows Phone 7 Mango update, you can run a small database call SQL CE in your Windows Phone app. The SQL CE database in Windows Phone use code first approach instead of the creating table first like what you did in your desktop or web development. This mean you will write the classes for your table in database and all the table will be generated on runtime when you run your app on the phone. Yes, you can’t manually create the table and insert the data into the database during your development.

Although the database has all the necessary functions basic function that you need, but if you have a large set of data that you want to insert into the database then you will have a problem. Generate a large set of data and insert into the database when user run your app for the first time was a bad idea, because it might take too long time and it will create a bad first impression of user when they first use your app. You can use XML instead of SQL CE, but on a large data set, XML performance is much slower than SQL CE.

In my case is, I have a huge XML file for my Windows Phone app (over 40 MB). Accessing to the XML file take me more than 20 second to initialize, it was a pain. Finally I found an alternative way to insert a large volume of data to the database. first I need to create a new Windows Phone project and I program it to convert my huge XML data to the SQL CE database (Phew, it take me 30 minutes to run the conversation). Then, I copy out the database from isolated storage and put it into the project I want. Done, my app can now direct access to the database and save ton of startup time.

For step by step how to do this, please refer to How to: Deploy a Reference Database with a Windows Phone Application

by Ooi Keng Siang via Ooiks’s Blog

In this post, I’m going to share my experience dealing with ListPicker which come from Silverlight for Windows Phone Toolkit (Sept 2010 edition). ListPicker is a very useful control to replace combo box type of control in Windows Phone, but currently version is too buggy and lot of work around needed. Here I’m share about the problem I face when using ListPicker and solution that I apply. Hope you can find it useful.

 

ListPicker Can’t Expend or Open Problem

This is a known bug in ListPicker. If you place the ListPicker in a ScrollViewer and the ListPicker can’t open in the full mode when user tap on it. The solution for this is manually open the ListPicker in FullMode when tap event is rise.

 

ListPicker Unable to Assign SelectedItem on Load / After User Select in Full Mode

Often we want to pre-select a SelectedItem in ListPicker which the application saved when the page load. The problem is if set  SelectedItem in page contractor like other controls, it still remain selecting the first item instead because it wasn’t loaded when you assigning  SelectedItem. If set on  PhoneApplicationPage_Loaded, it will work for the first time but when user tap on ListPicker and select a new value in full mode, the ListPicker will still remain the same SelectedItem. This is because  PhoneApplicationPage_Loaded will be call every time the page is load which mean when ListPicker full mode closed,  PhoneApplicationPage_Loaded will be call again and reset ListPicker SelectedItem again.

The solution for this is to put the SelectedItem in PhoneApplicationPage_Loaded event but make sure it is call one time only instead every time PhoneApplicationPage_Loaded is called. One way to do this use a class properties to keep track whatever ListPicker is initialized or not.

 

 

ListPicker Slow Performance Issue

If you have multiple ListPicker in the same page, you might notice the page will become unresponsiveness for the first one or two seconds when user navigate to the page. This is because multiple ListPicker take quite some time to load if you assign ItemSource in ListPicker during page constructor, on PhoneApplicationPage_Loaded event or on  OnNavigatedTo event. Setting  the CacheMode to BitmapCache won’t have solving the problem because it still need to load it for the first time.

I need the page to be responsiveness as soon as user navigate to the page. The only solution I can come out to solve this problem is to only load ItemSource to ListPicker when ListPicker is tap. Although this will cause ListPicker to open slower when user tap on it, but it is OK for me since I had more than 4 ListPicker and those ListPicker is just optional. Make sure you only assign ItemSource once instead of every time user tap on it.

 

That all for ListPicker currently. I hope all this information is useful for any one who face problem on ListPicker.

 

by Ooi Keng Siang via Ooiks’s Blog

In Windows Phone development, you can always assigning List<T> collection to a ListBox through ItemSource. If and only if you never remove any item in the List<T> collection before you assign the ListBox ItemSource to null first.

ListBox.ItemSource = SomethingList;

I encounter a situation where I display a list of items in a ListBox on my main page. Then user can to select the item in ListBox and edit or delete the item on the next page. Adding new item to the list or edit the item in the list doesn’t cause any problem at all. But if user delete any item on the second page and go back to the main page, the app will encounter an unexceptional error on App.xmal.cs. The error message show “The parameter is incorrect”, which give me no hint or clue what actually go wrong. Searching on the web for the error message or -2147024809 code give me no result at all.

 

After many testing I only figure out the problem that I assigning a List<T> collection to a ListBox was a bad idea especially the item can be remove by user during runtime.  The main problem here is ListBox won’t have know what happen to the List<T> collection when some items got removed on the other pages and yet it continue to assign to those items. The solution is simple, just replace the List<T> collection to ObservableCollection<T> collection. The different between List<T> and  ObservableCollection<T> is  ObservableCollection<T> will tell ListBox something changed and it need to update instead of crashing the whole app.

Now the problem had solved, but it doesn’t mean ListBox ItemSource must assigned to ObservableCollection<T> instead of List<T>. If the list of items wanted to display doesn’t change through out the app lifetime, it is still better to use List<T> because of it’s simplicity which save you more processing and memory.

by Ooi Keng Siang (Microsoft Student Partners) via Ooiks’s Blog