Monthly Archives: October 2017

Using the #mvvmlight DispatcherHelper in your .NET Standard libraries

.NET, .NET Standard, MVVM, Technical stuff, Universal Windows Platform UWP, Windows 10, WPF, XAML
No Comments

You might have heard that MVVM Light is now available as a .NET Standard 1.0 package, which means that you can use it in all your .NET Standard libraries (including 1.0, 1.4, 2.0 etc). Since .NET Standard is always backwards compatible, having MVVM Light running on .NET Standard 1.0 is quite convenient.

With .NET Standard, the incentive to use MVVM Light in even more applications is pretty huge, and with this the desire to use the DispatcherHelper to “translate” calls from a background thread into the UI thread of a UWP application, for instance. However as you might have already noticed, you cannot simply use the DispatcherHelper from within a .NET Standard library (nor from within a Portable Class Library for that matter). This is because the DispatcherHelper is a platform-specific component. In other words, the implementation for WPF is not compatible with the UWP or the Xamarin implementations. As a result, the DispatcherHelper class lives in the GalaSoft.MvvmLight.Platform DLL which gets added to your WPF, UWP or Xamarin applications, but NOT to your PCL or .NET Standard libraries…

The following article and sample propose a workaround. The article also details a few changes I want to add to MVVM Light to make it much easier to use DispatcherHelper in .NET Standard and Portable Class Libraries. Hopefully this will be useful!

Happy coding

GalaSoft Laurent Bugnion
Laurent Bugnion (GalaSoft)

Share on Facebook

Travels in October and November

Azure, Microsoft, Technical stuff, Visual Studio, Work, Xamarin
No Comments

These coming few weeks will be quite busy with conferences and other meetings. Here is where you might have the occasion to see me:

  • I am currently in Boston, where I will support Scott Guthrie’s Red Shirt Tour on October 19. Ultimately, Scott is my boss (‘s boss’s boss’s boss) as well as someone I have admire ever since I met him in person 10 years ago. The event is all about Azure with Scott showing demos and code across all of Azure, Visual Studio, Xamarin and more.
  • After Boston, I will be in New York City on October 20th. This is another stop of the Azure Red Shirt Tour.
The Red Shirt Dev Tour NYC edition will be livestreamed!! Join us at

  • Before going back home, I will have the privilege and pleasure to fly down to Lima, Peru on October 25th and 26th. There, I will participate to the MVP Connection event, organized by Microsoft for its Most Valuable Professionals. Unfortunately, due to travel constraints, I won’t have time to participate in any public event there, but I will most certainly do my best to come back at another occasion and speak in public.

At the MVP Connection event, I will have an hour to speak about a few exciting topics including Azure Functions and Xamarin, the Azure Mobile Center and the Xamarin Live Player. Of course I will also be available for questions and discussions around Azure, Xamarin, Windows, MVVM Light and more.

After a few days at home, I will continue with travel:

  • I will fly to Hyderabad, India and participate to another MVP Connection event on November 3rd and 4th where I will be honored to speak about the same topics as in Lima. There too, I will be available for questions and discussions, and meeting as many MVPs as I can :) Unfortunately I don’t have other stops in India in November, but I am already thinking of coming back next year!

Then I still have two conferences in November:

  • I am super happy that I can travel to Malmö, Sweden this year again and speak at the Oredev conference on November 10. I spoke there once in 2011 [TODO CHECK] and never could again because the conference was always conflicting with the Microsoft MVP summit. At Oredev, I will be speaking about HoloLens and show developers how to get started with Mixed Reality programming. This should work well with my dear friend Rene Schulte’s talk at the same conference, which is scheduled just after mine and will dig quite a lot deeper into the topic.

  • To conclude the travel in November, I will spend a couple of days in Sofia, Bulgaria on November 16th and 17th. There, I will have the honor of keynoting the ISTA conference. From their website: “Innovations in Software Technologies and Automation (ISTA) is an annual, international conference, devoted to the latest trends in software development and test automation. We are committed to support the development of quality standards in the field with focus on new technologies and best practices.” Sounds like a very exciting conference in a dynamic city of software. I had the pleasure to speak in Sofia before and was always impressed by the quality of the attendees!

I hope that I have a chance to meet some of you, dear readers, at one or the other event. Make sure to follow me on Twitter to get the details of my travels, and by all means come say hi!

Happy coding

GalaSoft Laurent Bugnion
Laurent Bugnion (GalaSoft)
Share on Facebook

Flexibility is great until it isn’t… Careful with these Azure Tables!!

Azure, Azure Storage Explorer, Azure Tables, Technical stuff, Work

As part of my ongoing discovery of Azure features and services, I am working on a few applications and samples that use various features of Azure such as Azure Functions, Azure Tables and more. Recently I had a bug in one of my applications, a link shortener that takes in a link in the form and returns another longer link, in this case

The application uses an HTTP Module that detects the short domain and performs the table lookup. This is straightforward enough. Where things become interesting is that by deploying this solution on Azure and switching Application Insights on, I get some feedback on who is clicking what. For instance, the short link above has a few possible variations. is used for Twitter, as indicated by the trailing T. I could also use for Facebook, for LinkedIn, you get the idea. It allows me to see where the majority of my community is active, which is interesting information.

Using analytics

As part of the service, I also have the possibility to add some analytics information for the destination system. For some Microsoft links, we use analytics like the following:


This type of analytics is used for the Red Shirt Tour taking place this Fall, where Scott Guthrie is visiting 5 locations in the USA and talking about Azure with a LOT of demos. If you haven’t done so yet, you should really check it out, some great content for free, and a chance to meet a lot of the Cloud Developer Advocates, including myself in Boston and NYC. Sometimes I want to use analytics, and sometimes I don’t, so I have foreseen a boolean column for this in the database, as shown below.

Using Azure Tables for storage

I found one small issue that cost me a few head scratches. You see, I use Azure Tables for the storage of the link information. This is quick to use and super easy to maintain. As time goes, I might port it to CosmosDB but for now, this works well.

From the Azure Tables page: “A NoSQL key-value store for rapid development using massive semi-structured datasets”. This is a very flexible, schema-less system. It means that you can easily add new entries in a table, and create new properties on the fly, for example with the Microsoft Azure Storage Explorer which I documented earlier. In my case, here is a screenshot of the table:

(Click for full size)

As you can see, the last column is titled SkipAnalytics. If true, the analytics portion described above is omitted from the long link. Obviously I made this value a boolean as shown in the class code:

public class ShortenedLinkEntity : TableEntity
    public string LongLink { get; set; }
    public string Alias { get; set; }
    public string Channel { get; set; }
    public string EventName { get; set; }
    public bool SkipAnalytics { get; set; }
    public string LinkAlias { get; set; }

The entities are retrieved with the following code. In this example, I hardcoded the index “5”, which corresponds to the RowKey column in the table shown above.

var account = CloudStorageAccount.Parse(Constants.ConnectionString);
var tableClient = account.CreateCloudTableClient();
var linksTable = tableClient.GetTableReference(LinksTableName);
await linksTable.CreateIfNotExistsAsync();

var retrieveOperation = TableOperation.Retrieve<ShortenedLinkEntity>(
var operation = await linksTable.ExecuteAsync(retrieveOperation);
var link = operation.Result as ShortenedLinkEntity;
return link;

The code above starts by creating a CloudStorageAccount corresponding to the connection string I obtained from the Azure Storage Explorer as shown here (Primary Connection String):


Then I create a CloudTableClient which I use to retrieve the CloudTable for the short links. To retrieve the entity itself, I use here the TableOperation.Retrieve method, which is very fast and convenient if you happen to know the PartitionKey and the RowKey for a given entity. Since in my code the RowKey is the index passed in the URL (here “5”), it is easy.

That sounds great, so where’s the issue?

Here is the bug: I wanted to add a new row. Eventually I will have a client for this (planning to develop it with Xamarin, of course, so I can use it on Windows, iOS, Android) but right now I add rows directly in the Azure Storage Explorer. Let’s see if you can spot the issue.

First I add a new entity in the table. Notice that I don’t enter a value for the SkipAnalytics column, this is an error that I will fix later.



Then I see ooops I forgot the SkipAnalytics column, let’s correct that now by selecting the row and clicking the Edit button.


Note that the empty columns are missing from this dialog. This is because as I explained, the entities stored in Azure Tables can take any shape, there is no strict schema. Freedom is great but in that case it will cause a small issue. Let’s add the missing SkipAnalytics column by pressing the Add Property button.


Looking good right? Now if I press Update, the entity is updated in the Table. I can then run the code to retrieve the entity in my web application and… SkipAnalytics is false. Why???

Did you spot the issue?

Let’s go back to the place where I edited the entity.


Wait… how can the column SkipAnalytics be a string? All the other rows use Boolean for this value in the table!! Well here you go, this is the issue. Because of the added freedom, I can have an object with a SkipAnalytics value of type bool, and another object in the same table where the SkipAnalytics value is of type string. When I retrieve the value in a strongly typed language like C#, I don’t get an error, but the value “true” maps to the Boolean false. Ugh…

Unfortunately, (1) the Azure Explorer doesn’t perform a check when you add an entity, (2) the Azure Table doesn’t have a problem storing what we would consider incompatible values and (3) there is no exception when the entity is retrieved and the values are mapped to the corresponding entity. This creates a bug in the application that can be quite difficult to understand.

What now?

For now, I didn’t ask the team yet why this is possible. I’d love to know if this is by design or if they would consider it a flaw of the system. What do you guys think? Personally I would be happier if the Azure Storage Explorer would prevent me from doing that. Maybe an update in the future? If and when I get a reply from the team, I will update this post with what I learn.

Happy coding

GalaSoft Laurent Bugnion
Laurent Bugnion (GalaSoft)

Share on Facebook