It’s always a good thing to provide information to the users of your application. One thing which may seem trivial is the version number. In fact it’s a really important information because with it the customers can send you a feedback with enough information to know in which version you have to fix the bug.
In ConsoTracker, the app I build on Windows Phone, I forgot to provide it and users ask met to provide it !
In this post you’ll discover that the classic .Net way does not work and how to retrieve it from your code.
Before I give you the code, be aware that the version number you set in your assembly is not read by the MarketPlace. In fact, you provide the information to it in the app submission process.
You do so have to update it in your code as you give the correct version to the market place.
How to do it ?
In .Net you can retrieve the version number of an application from it’s regarding assembly object instance.
If you try it on a Windows Phone, you’ll discover that calling the property throw an exception. Also, as pointed out by Thomas in a tweet, it’s security critical which restricts it to internal use by the .NET Framework for Silverlight class library.
That’s too bad because it would have been clean way to retrieve it. Instead you have to read the assembly name and deduce the version number from it.
Here is the helper I use in my application:
/// Retrieve the current version of the executing assembly.
/// This is the one in the AssemblyVersion attribute.
public static Version GetCurrentVersion()
var assembly = Assembly.GetExecutingAssembly().FullName;
var fullVersionNumber = assembly.Split(‘=’).Split(‘,’);
version = new Version(fullVersionNumber);
Be sure that the version number are synched if you put this code in another assembly. You can do this by sharing a file containing the AssemblyVersion attributes using ‘Add as link’ instead of adding a copy of the file.
Also, as it may represent a performance cost, I recommend you to to call it only once trough a static constructor.