Actually I lied in the title, I haven’t learned it today but there was a day when I’ve stumble upon this attribute in someone’s code and started using it ever since. This is one of these things that makes your life much easier while debugging. What does this DebuggerDisplay attribute do exactly ?

Let’s start from the beginning. By default when inspecting an object e.g. House:

we will se something like this:


You can say, but that’s not so bad, because we can inspect this object in details really easily by just expanding information about it, indeed:


As you know this process, which sometimes cannot be omitted, could drive you mad, especially when you are almost at the end of expanding really complex object and then you miss clicked the last expanding arrow, so everything collapsed, and you’ve to start ‘digging’ from the beginning. Even though it could be a painful process it’s pretty straight forward to inspect whatever information you’re looking for. Things could get bit more annoying when you’re dealing with collections.


This collection is just an example, of really small one, that still could be handled by this ‘clicking and expanding’ process, but imagine a collection with tens or hundreds of elements (probably you don’t have to imagine anything ‘cause you’re deal with those on regular basis) in which you want to check some deeply hidden property of a child of a child of a child of a child of your object. That would be a nightmare. With help comes DebuggerDisplay attribute which is used as simple as writing something like this

which gives us an effect of showing whatever information you need (even the one deeply hidden inside an child of a child etc.)


Now you’re ready to use it and make your debugging life much easier. BEFORE that, though, you have to be aware of some possibilities and good practices in this subject. You can write basically any code you want in the attribute {string}. This expression is going to be evaluated and than presented while debugging. Previous chunk of code (with DebuggerDisplay attribute) is BADLY written and I’ve put it only for exampling purposes. The first BAD thing about it is that it’s going to evaluate three expressions, and evaluation costs. Second BAD thing is putting a collection indexer reference in it, which can cause exception. So how it should look like ? Like this:

The best practice for DebuggerDisplay attribute is to use as less expression to evaluate as possible and this can be achieved using one property which is going to present your object as you wish. For more specific information(and what this ‘nq‘ thing is doing in the DebuggerDisplay attribute {string}) go to this msdn blog post, which explains in details good and bad practices. It’s not so long and it’s definitely worth reading

Not so long ago I had a small problem with inspecting pretty complex exception. Usually what you see after some exception is thrown is basically this kind of window:


I’ve highlighted Break when this exception type is thrown because without this box being ticked you won’t be able to see $exception pseudovariable inside your Watch window, but about that in a second. After seeing that, usually you click on View Details to check what exactly had happened:


Inspecting all of the provided information doesn’t give you much more information about Exception itself besides the type of it and that there are some more specific information inside the Exception (two exception parameters). Even though we don’t have much information about ‘insides’ of the exception we can tell something from exception name itself, right ? That’s correct, you can figure out what kind of exception or with which group of exceptions you’re dealing with, but you still don’t have specifics. With help comes mentioned earlier $exception pseudovariable.


As you can see there’s a lot information about exception that was thrown. For us the most important part is kept inside ConsoleApplication1.ComplexException:


Now you know exactly what had happened. You can do a little tweak around displaying it in the Watch window, so you won’t be bothered by other properties of Exception object. Just cast $exception to specific Exception type, like so


and voilla

Recently I’ve been doing some work with ASP.NET MVC, going back to the roots ;]. I had to create simple Web Portal to manipulate database tables. It had to have possibility to make CRUD (Create, Remove, Update and Delete) actions on tables records. I used MVC scaffolding option with specified model. After few clicks everything was generated for me, I mean Controllers and Views. Of course it wasn’t exactly as it was suppose to be, so I had to apply some changes. Making these changes I’ve realized that not everything is correct when it comes to models. Applied changes to models forced changes on the Views. In that moment I could just generate everything again but changes were only minor so it would take more time to make the ‘clicking’ than dealing with these changes on my own. What I’ve done to the models was simply deleting some properties. Everything look ready to compile, so I’ve tried. Errors occurred. Obviously, property that I’ve just removed from the model was used somewhere in the code and now compiler can’t find it’s representation. I’ve removed all of the problems and I finally could check how does the website look like in the browser:


Of course..yellow page of death showed up ;] There were still some references in the Views aka *.cshtml files that should be cleaned. One change, refresh page, another error, second change,  refresh page, another error, … , tenth change and so on and so on. So is there a way to put some guard or sentry to keep your Views compilable ? Yes there is! There is a big cost, though, that comes with it. Your build time will increase dramatically, but you can pretty easily switch it on and off whenever you need it. After major changes to your models just build it once with this function turned on, catch all the errors and switch it off afterwards.

What you have to do to get your Views to be compiled is rather straightforward. You need to change *.csproj file. You can do it in two ways. One is from Visual Stuido and the second just usual file edition from File System (Explorer). We will do it with VS. Let’s get this party started. First we have to unload our project so the *.csproj file could be edited.


After unloading, we’re going to edit our project file like so:


Now we should see *.csproj file and this is the place where we can force compiler to build our Views along with the code. All we have to do is to change MvcBuildViews setting to True or if the entry is missing just add it


Now you should see your compilation errors inside Error List window in Visual Studio

compilation_error_on_the_viewI’ve noticed that with MVC 5 this solution isn’t working, and what I’ve found out is that you need to add some extra stuff. In the same project file that you’ve been editing recently, at the very end of it, uncomment element

and add this code

You can read more about this topic on


What I’ve learned today

Quick explanation: This is going to be a title for a kind of series that I plan to make from a blog posts about my struggles, mistakes, obstacles, errors and problems that’ve encountered during development time. It’s going to be a log of a WP8 and WP greenhorn programmer trying to make his way through a maze of new stuff. Don’t expect some fireworks, it’ll be rhather kind of compendium of what to do when you stumble upon a particular problem. I hope it will help others like me to avoid same mistakes, ease the pain of searching over the internet for a solution to their issue, make their life easier or just learn with me. Let’s get started!

Favorite Time Zones

This project, about which I’ve mentioned in my previous blog post, is a simple idea of showing on the screen, of your device with Windows 8.1 or cell phone with Windows Phone 8.1 on it, current time in different times zones.

After starting new Universal App project from Visual Studio with at least Update 2 on board I’ve added MVVM Light Libraries and Time Zone Conversion for Windows Runtime and PCL with NuGet pakcage manager.


MVVM wasn’t necessary because of the pragmatic point of view you don’t have to apply MVVM concept to such simple application. The reason behind me adding MVVM Light to this project is simple, I want to do things right, following good practicies. After that my NuGet packages manager looked like on the screenshot below. CommonServiceLocator is atomatically added with MVVM Light.


I used Time Zone Conversion for Windows Runtime and PCL because it was no longer that easy to list all the time zones within Windows RT . Usualy you would be able to get all the time zones just like that:

With this library it was similarly easy:

And the model class, rhather obvious, but anyway I’ll put the code here, looks like this

Having that, we can proceed further. We will be showing time, so it has to be ‘refreshed’ or ‘updated’ accordingly, like a watch. The first concept of welcome page of Favorite Time Zones project looks like this:


At the top, there will be displayed users current time and underneath it there will be a list with favorite time zones. After a little bit of design of the page, I put a lot of emphasis on little, we can start playing with some logic around it. First thing we do, is to get the user time clock to work. Usually you would create a Clock.cs class and imitate time lapsing with System.Threading, inifinite loop and Thread.Sleep(). Maybe it’s not the best way  to create clock when you have to be really precise, but for our purposes it’s enough. To start new Thread you could do something like, right ?

No, you cannot. Not in a framework for Universal Apps, with them you have to use Tasks. This implicates that we can no longer use Thread.Sleep(), but with help comes Task.Delay(), its equivalent. No worries, we can use Tasks, although I’m rhater used to Threads. After a while you will find Tasks really useful, because of their usage with async and await functions, that really simplifies things. But let’s stay on the topic of updateing our clock. Clock itself could look like this

It has a ctor() that takes tick interval and has one public method, Start(). Although, the most important part is the Tick event handler that we will register to and we will update our clock once the event is invoked. ClockStart() method is an endless loop, called from ClockStart() in a separete Thread (Task), that ‘Ticks’ every specified interval time. In our case it’s going to be 1 sec. Let’s then start our clock and register to its tick event.

This is our ViewModel class for MainPage. It inherits from ViewModelBase (MvvmLight). It provides implementation for INotifyPropertyChanged interface and gives us easy way of communicating to the View that some changes in the ViewModel have been made. This notification mechanism is done with RaisePropertyChanged method. In the ctor() we are creating a Clock (not the best place for it, but this is done only for the example purposes) and registering EventHandler for the Tick event and then we Start() the clock. Everything looks great. Clock is working, Tick event is fired and ‘captured’ so we could refresh View and its done with RaisePropertyChanged. Should work, right ?

the_application called_an_interface_that_was marshalled_for_a_different_thread

This is what you’ll get. Exception, telling you that some thread wanted to access area that he wasn’t allowed to enter.

The application called an interface that was marshalled for a different thread

This is rhater obvious when you think about it. I’ll relate this situation to a real life one. Let’s say you are driving a car and next to you sits a passanger. You’re on a long and boring drive (Main Thread), straight road for hundreds of kilomiters, and all of a sudden, you don’t know why, your passanger is trying to grab the wheel and turn the car (different Thread). So what do you do ? Of course you are going to slap his hand(s) and ‘revoke’ his try to kill you and himself. This rule applies even when it comes to a radio station, slap ;] ! What in a situation if passanger had a really good reason to try to interrupt you ? Like, we are going to miss a turn or they started to play Justin B. on the radio. So the passanger could succeed with his intentions and actions, he is obligated to say to a driver ‘listen, you should take next turn left’ or in our case ‘listen, there is something that you should update on your view’ and then the driver, who has proper permisions, will respond with an action. This is done through a DispatcherHelper and CheckBeginInvokOnUI() method in MvvmLight library.

It works!

Windows Phone 8.1 and Windows 8.1 developer

Recently I’ve had a little change in my carrer. From being a .NET Web Developer I’ve become (at least trying to become) Windows Phone & Windows 8 Developer. Almost everything is different, minor change ;]

Right now on regular basis I’m dealing with XAML, MVVM concept, MVVM libraries, Blend, Animations, VisualStates and much more stuff that comes with creating applications for Windows Phone (WP) and Windows 8 (W8) platform. Although I had some, none professional, experience with Windows Phone and all that I’ve mentioned above – I’ve made 3 really simple applications – it was a drop of knowledge in the sea of stuff that you have to know as a decent WP and W8 programmer.

With that being said, I’m trying to catch up, bacause of the obvious lack of knowledge, and in my spare time I’m doing some easy projects that hopefully will let me understand better the concepts, best practices, syntax, libraries and everything that hovers around the WP and W8 development. Keep your fingers crossed.

Universal Apps

Lately Microsoft presented new way of building apps for WP & W8. Universal apps, that’s the name of the idea, allows you, as a developer, to create only ‘one’ application for both earlier mentioned platforms. That’s truly great, like a special offer in the shop, 2 for 1, more for less. What’s even better, it’s a new thing in a .NET world and I’m new to this particular part of a .NET world. Everybody knows that two negatives gives plus. Isn’t it great ;] ? So! Besides reading about it

I figured out that theory isn’t enough and it would be good to do some practical exercises. Brilliant idea! I wasn’t thinking more and just started coding. Not really…Firstly you have to download and install Visual Studio 2013 Update 2*. Read what’s new in it here and download it from here.

Visual Studio 2013 Update 2

After a while you can create your first Universal Application. Just choose a template, pick a name for a project and you’re ready to go.


First Universal App project – Favorite Time Zones

The application that I’m going to create is really simple one, and you can find a lot similar ones already in the store, but that’s not the case here. The deal is to learn about WP8 and WP platform, API, possibilities, limitations, behaviour etc.

Idea came from a need. Right now I live in Australia but originally I’m from Poland and sometimes I want to call my family and I don’t know what exact time is in Poland, same thing goes for my family but in the opposite way. It’s 8h difference, which can be easily calculated but if there was a tile on my phone or laptop screen with my Favorite Time Zone(s) that would be great. No more calculations, just a quick glimpse and I know if I can make a call or not. Let’s get to work then.

To be continued…

 * Apparently there was another package of updates. Now you can download Update 3 for Visual Studio.