Notes from Daily Encounters with Technology RSS 2.0
# Sunday, February 22, 2015

One of my coworkers suddenly encountered the following error in a large .NET application we're developing:

'ResourceDictionary' root element is a generic type and requires a x:Class attribute to support the x:TypeArguments attribute specified on the root element tag.

Of course the ResourceDictionary class in question wasn't generic, hence the error made no sense. To make matters worse, no changes were made to the file since it was checked out from source control; and that version of the project compiled fine.

  • We started randomly reverting different changes in the working copy - without success.
  • We tried to compile the same code on a different machine, just to make sure there wasn't something wrong with the developer's copy of Visual Studio - it failed the same way on other machines.

Eventually we ran out of ideas and decided to check whether anyone else has encountered this issue before. Sure enough, we found a MSDN forum post with exactly the same issue. The solution for the problem made no more sense than the problem itself: add the x:Class attribute to the root element as suggested in the error message. Its value doesn't really matter and can be anything.

This was enough to resolve our issue, but I couldn't let the matter rest without investigating it further. After reading the forum thread in detail a couple of times, I started looking for a simple way to reproduce the issue in another project. It turned out you need at least 3 classes in your project:

  • A generic class derived from UserControl:
public class GenericBaseUserControl<T> : UserControl
    public T Property { get; set; }

  • A custom user control deriving from it:
<genericResourceDictionary:GenericBaseUserControl x:TypeArguments="system:String"
    d:DesignHeight="300" d:DesignWidth="300">


  • A ResourceDictionary importing the namespace with the above custom control:
<ResourceDictionary xmlns=""

That's enough for the bogus compile error to appear. I know of 2 workarounds to avoid the issue:

  • Remove the namespace containing the problematic custom control from the resource dictionary if you don't need it:
<ResourceDictionary xmlns=""
                    <!-- No GenericResourceDictionary namespace, no compile error -->

  • Add the x:Class attribute to the ResourceDictionary element:
<ResourceDictionary xmlns=""
                    x:Class="Whatever"> <!-- This attribute fixes the build -->

In spite of these known workarounds I decided to report the issue to Microsoft Connect. I don't want other developers wasting their time on this strange compiler error, like we did. Feel free to upvote it, if your opinion is the same.

Sunday, February 22, 2015 6:35:06 AM (Central European Standard Time, UTC+01:00)  #    Comments [0] - Trackback
Development | WPF
# Saturday, February 21, 2015

Slight differences between XAML platforms can quickly throw you off track when switching between them. While I was recently writing my first WinRT application for Windows Phone 8.1 I spent more time than I should have, looking for a way to invoke a command on the view model from an event. Due to the changing nature of WinRT and Windows Phone platforms, it's difficult to find up-to-date information on the topic, therefore I'm writing this blog post as a future reference for myself.

On most platforms MvvmLight includes a helper class to make that work, so the most common advice you'll find, will be to use that. In WinRT the class is suspiciously missing. Not only that; at first sight there is no Interactivity namespace either. Fortunately, that's not true; since Windows (Phone) 8.1 it is in fact included in the Behaviors SDK extension which you can reference from your project. In that same extension the replacement for the missing EventToCommand trigger is available as well: it's called InvokeCommandAction.

Taking all that into account, triggering commands from events actually becomes pretty easy:

  • Add reference to Behaviors SDK (XAML) extension from your project via Reference Manager dialog:

Behaviors SDK (XAML) in Reference Manager

  • Add the Microsoft.Xaml.Interactivity namespaces at the top of the page:
<Page xmlns:interactivity="using:Microsoft.Xaml.Interactivity"

  • Use InvokeCommandAction in your page to invoke the command when an event is triggered:
    <core:EventTriggerBehavior EventName="Loaded">
        <core:InvokeCommandAction Command="{Binding ActivateCommand}" />

That's it: when this page loads, it will invoke ActivateCommand in its DataContext.

Saturday, February 21, 2015 12:46:15 PM (Central European Standard Time, UTC+01:00)  #    Comments [0] - Trackback
Development | Metro | MvvmLight | Windows Store | WP
# Saturday, February 14, 2015

Dr. Alex Blewitt: Swift EssentialsOnce again I got an opportunity to broaden my horizons a bit while reading a book for review. This time it was Swift Essentials by Dr. Alex Blewitt. With almost no prior experience with Objective-C and iOS development, I am just the person, the book is targeting. Of course I also didn't have any prior exposure to Swift, except for a couple of snippets I looked at when the language was first announced.

The author kept the initial introduction to the basic language syntax really brief and quickly made it more interesting and rewarding by replacing the command line REPL environment with Xcode integrated development environment and its playgrounds - a feature which provides a highly interactive environment for experimenting with the language. Not only that: he moved on to development of basic iOS applications, even before he covered all of the language features; introducing many of them only when they were first encountered in sample code.

Major part of the book is actually a step by step guide to iOS development in Swift for complete beginners. By the end of it the readers should have enough knowledge to write their first simple iOS application even without any previous experience. Along the way all the key concepts of the API are explained in detail, as well as a couple of peculiarities originating from the Objective-C era which could cause memory leaks or prematurely released memory, if not handled correctly. Even unit testing of Swift code was mentioned and encouraged.

The only thing I missed, was a more in-depth discussion of the language features and how they will impact the way the code will be written in it. Though, considering the target audience, it's not really fair to hold that against it. If nothing else, it makes up for it with a very extensive list of resources about Swift and iOS development which should satisfy even the most curious reader.

The book is available on Amazon and sold directly by the publisher.

Saturday, February 14, 2015 5:16:53 PM (Central European Standard Time, UTC+01:00)  #    Comments [0] - Trackback
Development | iOS | Swift | Personal | Reviews
# Saturday, January 31, 2015

On Tuesday Microsoft Slovenia organized the second TechDays event leading up to the 20th NT conference which is returning to Portorož in May this year. The event consisted of 4 tracks; I had the opening session for the Visual Studio 2015 track.

After the introductory mention of Visual Studio Community 2013, I focused on an overview of new features from the publicly available Visual Studio 2015 Preview:

  • .NET Compiler Platform (formerly known as Roslyn) and changes to the editor
  • first look at NuGet 3
  • improvements to shared projects
  • Smart Unit Tests, a production-ready of Microsoft Research project Pex

The features which I skipped where covered in subsequent sessions by other speakers: support for development in Cordova, diagnostics, debugging, and Visual Studio Online.

As always slides and demos from my session are available for download.

I hope the attendees enjoyed the event as much as I did as a speaker. I'm already looking forward to Portorož.

Saturday, January 31, 2015 3:25:37 PM (Central European Standard Time, UTC+01:00)  #    Comments [0] - Trackback
Development | C# | NuGet | Testing | Downloads | Presentations | Software | VisualStudio
# Sunday, January 25, 2015

For some reason display drivers for both NVIDIA and AMD graphics cards have a tendency to scale image to full panel size instead of keeping the default aspect ratio. If you don't like to see your image stretched, you can change the behavior in the corresponding control panel (NVIDIA Control Panel or AMD Catalyst Control Center, respectively). The setting also doesn't persist reliably across driver updates, so it needs to be reconfigured occasionally even if it was previously set correctly.

On top of that after recent driver updates both control panel applications got broken somehow on two desktop machines I'm taking care of:

  • The NVIDIA one failed to show most of the settings - only Stereoscopic 3D settings were available in the tree view; nothing else.
  • The AMD one was just reverting the settings to their previous value immediately after applying them.

Today I decided to get to the bottom of the issue and finally correctly configure the driver again.

It seems NVIDIA Control Panel doesn't play well with other display drivers installed on the machine. Based on this information I tried to disconnect my USB monitor and it helped: all of the configuration options were available again. Obviously NVIDIA drivers don't coexist well with DisplayLink ones, required by the USB monitor.

Once the missing settings in the control panel reappeared, configuring them correctly is pretty trivial:

  1. Open Display > Adjust desktop size and position from the tree view.
  2. Select the display you want to configure.
  3. Set scaling mode to aspect ratio.
  4. Set scaling to be performed on GPU.
  5. Override the scaling mode set by games and programs.

This is how the end result in the current version of NVIDIA Control Panel:

Image Scaling Settings in NVIDIA Control Panel

AMD recently released a new generation of their display drivers: AMD Catalyst Omega. After the upgrade changing the scaling settings in AMD Catalyst Control Center didn't seem to have any effect any more. Fortunately I wasn't the only one having this issue. As suggested in the post, I removed my display adapter from Windows Device Manager, selecting to delete the drivers as well.

Reinstalling the latest drivers after doing that fixed the issue, making it possible to apply the required configuration:

  1. Select My Digital Flat-Panels > Properties (Digital Flat-Panel) in the navigation pane on the left.
  2. Select the display you want to configure.
  3. Enable GPU up-scaling.
  4. Select Maintain aspect ratio as Preferred Scaling Mode.

This is a screenshot of the final settings from the current version of AMD Catalyst Control Center:


Sunday, January 25, 2015 1:49:44 PM (Central European Standard Time, UTC+01:00)  #    Comments [0] - Trackback
Software | Windows
My Book

NuGet 2 Essentials

About Me
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

All Content © 2015, Damir Arh, M. Sc. Send mail to the author(s) - Privacy Policy - Sign In
Based on DasBlog theme 'Business' created by Christoph De Baene (delarou)
Social Network Icon Pack by Komodo Media, Rogie King is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.