Category Archives

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 http://aka.ms/rstlive

  • 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
Laurent

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
5 Comments

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 http://gslb.ch/5t and returns another longer link, in this case https://expertday.forxamarin.com.

The application uses an HTTP Module that detects the short domain gslb.ch 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. http://gslb.ch/5t is used for Twitter, as indicated by the trailing T. I could also use http://gslb.ch/5f for Facebook, http://gslb.ch/5l 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:

“?WT_mc_id=redshirtdevtour-twitter-lbugnion”

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:

2017-10-01_11-05-22
(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>(
    "partition",
    "5");
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):

2017-10-01_11-20-54

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.

2017-10-01_11-25-29

2017-10-01_11-26-21

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

2017-10-01_11-32-01

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.

2017-10-01_11-33-47

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.

2017-10-01_11-33-48

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
Laurent

GalaSoft Laurent Bugnion
Laurent Bugnion (GalaSoft)

Share on Facebook

Writing, writing, writing…

.NET, Azure, Azure Functions, Cloud Developer Advocate, Microsoft, Technical stuff, Work, Xamarin
No Comments

One thing I love in my new job is that I can just sit down anywhere on Earth, grab my Surface Pro and produce content (articles, samples, etc) or learn new things just as if I was home. I just came back from Singapore and had a great time there talking at the Xamarin “MonkeyFest” conference. But it was also a busy time producing content and I am so happy that things are starting to fall into place.

Here are a few highlights:

  • I just published a few new articles (see below). As I am discovering new features of Azure, I want to share with you all. I decided to write in markdown (just like docs.microsoft.com) and publish on GitHub. Why GitHub? Well first of all this is of course the destination for developers. The markdown renderer is pretty good, it is easy and fast to create and publish good quality content. At some point this documentation might migrate to another location, but for now it makes sense to have it on Github. Also, and maybe most importantly, I like that the source code and the corresponding articles are all grouped together, for example my sample-azure-coinvalue application.
  • As I was writing, I noticed that a few topics are going to be recurrent in all my samples. So I went ahead and created the following repo: sample-azure-general. In this repo, I will document recurring processes in Azure, such as creating a trial account, Creating and testing Azure Functions in Visual Studio, Publishing functions to Azure, etc etc etc.
  • In parallel I am also working on new samples and should be able to publish more soon. So stay tuned to this blog or to my Twitter account. Yes for now the list of samples is very lean but now that everything is starting to be coherent, I want to add new content regularly!

Please help me help you!

I’d really like you all to be able to tell me what is the most important for you. And so in this spirit I want to start with two features:

Available articles:

At the moment you can find the following content in sample-azure-general:

Hopefully this is helpful to all of you, and I hope that we can get the discussion running. Microsoft is literally paying me to help you understand Azure, cross-platform, Windows, .NET and more and I love that job. So please please please don’t be shy and let me know what you need. We want to help!

Happy coding
Laurent

GalaSoft Laurent Bugnion
Laurent Bugnion (GalaSoft)
Share on Facebook

My talks in September

.NET, Azure, Azure Functions, Microsoft, MVVM, Work, Xamarin
No Comments

I don’t know about you but I had an amazing summer. I had the amazing luck of spending time in beautiful places in the Philippines, Iceland and then 2 great weeks in Seattle and Redmond. Having started to work with Microsoft on August 1st, it was great to be on campus in Redmond as a blue badge.

Apart from sitting down with my new team, meeting my new manager and old friends on campus, I also delivered two sessions at the Visual Studio Live conference. The event took place at the Microsoft conference center (Building 33) and was as packed as usual with great speakers and very competent attendees. This year was special for me because my two talks took place in the Cascade room, which is a really nice auditorium with all the comfort. I also had a lovely time interacting with attendees at the traditional Birds of a Feather lunch, where a table is assigned to a speaker and attendees can go around the room, sit down, ask questions or just chat.

You can find the slides, source code and all the information about my two talks on my website:

Amsterdam: MVVM Cross Hackfest

My next engagement is the closing event of the MVVM Cross Hackfest taking place in Amsterdam on September 2nd. The .NET Open Source foundation is sponsoring this event with others, where the aim is to encourage new contributors to help open source projects. For MVVM Cross, the event is the occasion to port this popular framework to .NET Standard. While the project lasts 2 weeks, September 2 will be the last day with a celebration, some lightning talks and a party.

At this occasion, I will speak about Azure Functions (which are really awesome). My Microsoft colleague Mike James will also be there and speak about other Azure services. The rest of the lightning talks will be held by MVVM Cross contributors. You can see the program here. My session’s abstract is the following:

Azure Functions and Xamarin

One of the most exciting recent additions to Microsoft Azure is called Functions and allows the developer to quickly build and deploy code to the cloud without complicated setup. Also dubbed “serverless computing”, Azure Functions can be triggered by timers, HTTP calls or database operations, and can communicate with other Azure services or mobile and desktop applications such as those made with Xamarin. In this lightning talk, Laurent Bugnion, Cloud Developer Advocate for Microsoft, will give you an introduction to Azure Functions and get you started with this exciting aspect of modern computing.

Singapore: MonkeyFest

A little later in the month, I will fly to Singapore to attend the MonkeyFest conference which is a Xamarin event organized for the first time in the beautiful south east Asian city. There is a nice team of speakers speaking on a variety of topics. The entrance tickets can be purchased for 19 Singapore dollars, which is very cheap for such a quality show! We hope to see a lot of attendees at Microsoft Singapore!

Building truly Universal applications with Windows, Xamarin, MVVM and Azure

With Windows 10 supporting an unprecedented number of platforms and form factors (from IOT to phones to tablets to laptops and desktops to XBOX and SurfaceHub, and even the new HoloGraphic computer HoloLens), the name “Windows 10 Universal application” is fairly accurate. But to be honest, shouldn’t a truly Universal application run on Windows 7, iOS and Android devices too? Thankfully, this is possible thanks to a clever architecture pattern named Model-View-ViewModel, the .NET portable class libraries and the Xamarin frameworks. With these tools, we can structure an application so that most of the code is shared across all the platforms, and then build truly native UI that adapts without any compromises to the device it runs on. In this session, we will understand exactly how such universal applications are built. Laurent Bugnion, a XAML/C# expert, Microsoft and Xamarin MVP who started making universal applications before it was even a thing, will show you practical knowledge with a lot of demos. Come listen from the creator of the popular MVVM Light Toolkit how this powerful but simple library can be leveraged to help you target more users than you ever dreamed of!

Come say hi!

I hope that I will have the occasion to see a lot of you out there. I have more talks coming up in November – but that is for another post. Please come say hi!

Happy coding
Laurent

GalaSoft Laurent Bugnion
Laurent Bugnion (GalaSoft)

Share on Facebook

Running unit tests on Azure Functions in Visual Studio 2017

.NET, Azure, Azure Functions, Microsoft, Technical stuff, Visual Studio
No Comments

TL;DR; You should really update your Nuget packages

I am currently experimenting a lot with Azure due to my new job and also of course due to the really cool innovation that we can find there. Recently I got interested in Azure Functions. This cool feature allows to write a small piece of code that runs on Azure and can be triggered by various events (time based, HTTP-request based, etc). For example, imagine that you have a value that keeps changing and you want to monitor this value and do some kind of analytics on this. In the code I am currently writing, I am using the value of a Bitcoin as the sample, and I am just periodically reading this value and storing it into an Azure database.

For this small functionality, it would be much too complicated to set an entire server-based application up. This is a perfect example for a time-based Azure Function. I am not going to explain more about Azure Functions here, because I am working on a complete article including sample which will do that. But in the course of my investigation, I stumbled upon an issue that can easily be solved.

The problem:

The issue arises when you try to write unit tests for your Azure Function. In many examples I saw, the Azure Function was created straight in the Azure portal, which is great but makes it a bit difficult to unit test the code. Thankfully it is also possible to create the Function project in Visual Studio, and to take advantage of all the features including unit test, code coverage etc.

To do this, try the following:

  • Install Visual Studio 2017. I currently have the Update 3, which is the most recent at this time. Make sure to select the Azure workload when you install Visual Studio!

Click to see the full picture

  • In Visual Studio, select Create new project.
  • In the New project dialog, select Cloud on the left, and then Azure Functions.
  • Give your project a name and then click OK.
  • Right click on the Function project and select Add, New Item.
  • In the Solution Explorer, right click on the solution and select Add, New Project.
  • In the Add New Project dialog, select the Test category, and then Unit Test Project (.NET Framework).
  • Give your unit test project a name and then click OK.
  • In the Unit test project in Solution Explorer, right click the References folder and select Add Reference.
  • In the Reference Manager dialog, select Projects and then the Function project that you created earlier. Then click OK.
  • Build the solution.

If you have the same setup as I have, you will get an error stating something like:

Metadata file ‘C:\Users\Laurent\Documents\Visual Studio 2017\Projects\FunctionApp2\FunctionApp2\bin\Debug\net461\FunctionApp2.dll’ could not be found

Indeed, if you check the path in Windows Explorer, you will see that there are no DLLs under FunctionApp2\bin\Debug\net461. There is however a folder under FunctionApp2\bin\Debug\net461\bin which contains all the DLLs. The issue is that the Functions project does not generate its output to a standard path. As a result, the Unit test project does not find the reference it was expecting.

The resolution

After reaching out to the Azure Functions team, I found out that this is a know issue and that an updated project template for Visual Studio will be released soon. But there is already an easy fix that you can apply to your project today: You just need to update your Nuget packages, and this will apply the fix to the Functions project.

  • In the Solution Explorer, right click on the Solution and select Manage Nuget Packages for Solution.
  • Under Installed, select the Microsoft.NET.Sdk.Functions package.
  • On the right under Versions, select the Function project. Note that the version shown is smaller than 1.0.2 (likely 1.0.0).
  • Below this box, make sure that Latest stable 1.0.2 is selected in the Version combo box and then click Install.
  • Build the project again. This time it should succeed.

Click to see the full picture

Conclusion

This was an easy fix that the Azure Functions team was able to deploy to your project using an update to the Nuget package. Of course, there are good reasons why teams are sometimes reluctant to apply an update: They might fear that the update brings breaking changes, or that something might go wrong unexpectedly due to regression bugs etc. But when you create a brand new project, it is a good idea to apply the Nuget updates to the solution. This way you will make sure that your new project starts with the latest and greatest.

Thanks to the Azure Functions team for their help solving this issue!

Happy coding
Laurent

GalaSoft Laurent Bugnion
Laurent Bugnion (GalaSoft)
Share on Facebook