Rico Suter's blog.
 

Azure DevOps: My versioning flow to publish .NET packages from a GitHub repository
This guide shows how to enable CI/CD builds to handle versioning and publishing .NET projects from a GitHub repository to NuGet feeds.
Read More ›

Dependency Injection in .NET: A way to work around missing named registrations
The default .NET dependency injection container does not provide a way to register named services. This article shows a technique to solve this by adding a generic marker parameter to the service interface so that it can be registered multiple times and resolved with the marker type.
Read More ›

Logging with ILogger in .NET: Recommendations and best practices
This blog describes and outlines some best practices for using new the logging system which has been introduced with .NET Core but is also available in all .NET Standard 2.0 supporting .NET frameworks.
Read More ›

Technology Summary: Azure Blob Storage
Microsoft Azure Blob Storage is used to store big chunks of binary data to access from other cloud services. The technology is mainly used as replacement for a shared file system which is not available in the cloud.
Read More ›

Azure DevOps: How to update the Azure Function default Host Key in a PowerShell task
For a recent project I dynamically create new Azure Functions in an Azure DevOps release pipeline. One of the requirements was to automatically update each default Host Key to a given value so that it's easier to access the newly created HTTP functions.
Read More ›

Azure DevOps: Create a Web App for Containers CI/Release pipeline for an ASP.NET Core app
This article shows how to create a Web App for Containers CI/Release pipeline for an ASP.NET Core app.
Read More ›

C# 8: The output of Nullable Reference Types and how to reflect it
After reading some articles about the new C# 8 feature Nullable Reference Types, one question still was unanswered: How does a compiled assembly with nullable types enabled look like and how can I access the nullability information via reflection? Because I couldn't find an article with an answer, I had to figure it out myself.
Read More ›

Missing SDK when using the Microsoft.Build package in .NET Core
How to fix the missing SDK error when using the Microsoft.Build package in .NET Core.
Read More ›

Use private Azure DevOps NuGet package feeds with the .NET Core CLI
If you have a .NET Core project which references a NuGet package from a private Azure DevOps package feed, you cannot just build the project in CLI because you are not authorized to access the feed: When running dotnet restore, you’ll end up with this error message:
Read More ›

How to publish an NPM package in AppVeyor
For some open-source projects I need to publish NPM packages during the CI release on AppVeyor. Unlike with NuGet packages, you have to do that manually by installing NodeJS and NPM, creating an .npmrc file with your NPM credentials and publishing the package. This blog post describes this procedure in detail.
Read More ›

Automatically migrate your Entity Framework Core managed database on ASP.NET Core application start
If you use Entity Framework Core with migrations in your ASP.NET Core application and want to ensure that the database structure always matches the currently running application, you can simply migrate the database on application startup. This way you just have to redeploy your application and everything like migrating the data, change the schemas, etc. is done when the application is restarted.
Read More ›

Advanced Newtonsoft.Json: Dynamically rename or ignore properties without changing the serialized class
This article describes how to implement a custom contract resolver, so that you can ignore or rename serialized JSON properties where the serialization happens and without changing the serialized classes.
Read More ›

NSwag Tutorial: Implement a custom operation processor to define ReDoc code samples
With NSwag you can implement custom operation processors and apply them to ASP.NET Core MVC or Web API controller operations. These processors then get picked up by NSwag and are applied to the given operation in the Swagger specification.
Read More ›

How to instantiate a generic type in TypeScript
This article shows how to instantiate a generic type in TypeScript.
Read More ›

Use T4 TextTemplatingFilePreprocessor in .NET Standard or PCL libraries
For my projects NJsonSchema and NSwag I wanted to use T4 templates to programmatically generate code generating code (TextTemplatingFilePreprocessor). Adding the .tt file with its generated C# class works, even if the files are added to a PCL (Portable Class Library) or .NET Standard 1.0 project. The problem is, that the produced code does not compile because the used PCL Profile 259 (same as .NET Standard 1.0) is missing some required classes and reflection methods. To fix the compiler errors, you have to provide the missing types and methods in your assembly. To avoid name collisions with potential client assemblies you need to declare all these extensions as internal and as a consequence the generated class too (this may be a deal-breaker).
Read More ›

Aurelia JS: Detect dirty checked properties during development
I am currently working on new single-page web application based on the Aurelia framework. To avoid performance problems, we want to completely avoid dirty checked properties and method calls. Bindings are dirty checked whenever the framework cannot use another mechanismn than regularly polling for changes. It is important to detect dirty checked properties as early as possible so that they can direcly be avoided and not too many depenencies have to be changed.
Read More ›

Implement custom MSBuild tasks and distribute them via NuGet
In this article describes how to implement MSBuild tasks with inline C# or in an external .NET assembly. After doing so, we will bundle these tasks in a NuGet package, so that they can easily be distributed and updated via NuGet and executed as part of the MSBuild compilation process. This is a powerfull technique to share and manage MSBuild tasks (e.g. build scripts, code generators, etc.) in bigger environments (enterprises, open-source libraries, common/shared tasks).
Read More ›

Aurelia JS: Implement a dialog service which renders Bootstrap UI dialogs
I’m currently working on an SPA (single-page application) which uses the Aurelia JavaScript client framework and Bootstrap UI CSS framework. In the application I need to show various custom dialogs. This is why I implemented a reusable dialog service class which simplifies the creation of Bootstrap based dialogs. In this article I’d like to share and explain the code of this dialog service and the required helper classes. The sample code is written in TypeScript but it can easily be converted to ES6 JavaScript.
Read More ›

.NET Core: Missing mscorlib after installing a Portable Class Library (PCL) or .NET Standard library
.NET Core projects can reference Portable Class Libraries if one of the .NET Standard compliant profiles is used (e.g. the profile 259).
Read More ›

NSwag Tutorial: Generate an Angular TypeScript client from an existing ASP.NET Web API web assembly
This tutorial shows how to generate an Angular TypeScript client with the NSwag Swagger toolchain. You can use this client in your Angular 2 SPA (single-page application) to consume the web services of an existing Web API project. The metadata for the client generator will be loaded from an existing .NET assembly which contains your Web API controller classes. The NSwag project provides many other TypeScript templates (for targeting other JS frameworks) and also a C# client generator.
Read More ›

NSwag Tutorial: Integrate the NSwag toolchain into your ASP.NET Web API project
This tutorial shows how to integrate NSwag (Swagger toolchain for .NET) so that you can access your Web API actions with the Swagger UI and a generated C# client library.
Read More ›

Script to clone all Git repositories from your Azure DevOps collection
In this article I show you a PowerShell script which clones and pulls all Git repositories from your Azure DevOps collection. I use this script to retrieve the complete code base so that I can run my code analysis tools on it.
Read More ›

SystemJS module loader: Enable JavaScript debugging with Visual Studio and Internet Explorer
In a project, we switched from the JavaScript module loader RequireJS to SystemJS. After the migration, debugging JavaScript directly from Visual Studio in Internet Explorer stopped working. The problem is that Visual Studio cannot detect the loading of script files because SystemJS uses JavaScript HTTP calls instead of injected tags to load modules.
Read More ›

How to programmatically retrieve the deployment time of an ASP.NET web site
In one of my web projects, I wanted to append the web site deployment time to the JavaScript URLs. This way the browser uses the cached file version until a new web site version is deployed.
Read More ›

OpenLayers 3: Add the Bing Maps Traffic layer to your map
The following code shows how to add the Bing Maps Traffic layer to your OpenLayers 3 map.
Read More ›

JavaScript decorator to add pre- and post-logic to a Promise
In this blog post, I’ll describe the simple concepts of JavaScript Promise decorators. They are a simple way to add logic which is run before and after the exection of a Promise (a.k.a. aspect-oriented programming). As soon as you see my two samples, you’ll get the idea…
Read More ›

Asynchronously loaded Unit Tests with Jasmine and RequireJS
The following check list shows how to write JavaScript Jasmine Unit Tests where the tests are asynchronously loaded from AMD modules with RequireJS.
Read More ›

Angular: Convert input values to the correct type with a TypeScript property decorator
I recently played with Angular and found an uncomfortable problem: Declaring an input property with a TypeScript type does not guarantee that the input value will always be of this type. This is because the Angular framework may update an input with a wrongly typed value and thus is able to “circumvent” the TypeScript type system. As a result, you may end up with strange and unexpected runtime errors.
Read More ›

Migrate a TFS repository to a Azure DevOps Git repository
To migrate a TFS repository to a Azure DevOps Git repository, just perform the following steps.
Read More ›

JavaScript Promises: Tips, tricks and best practices
JavaScript Promises are a very powerful tool to avoid the callback nesting hell. The following article describes some tips and tricks when working with Promises. For developers with C# async/await knowledge, I will also show the async/await representations. With TypeScript, you can use this async/await syntax today.
Read More ›

Inside Async/Await: Synchronize an async method or code block
Have you ever tried to await a task inside a lock() block? It is not possible, because you can only synchronize synchronous code with the lock keyword. However, in today’s .NET development, async/await is used everywhere and the need to synchronize asynchronous code blocks is coming up quite often. This is why I wrote a simple class which can be used to synchronize asynchronous code blocks.
Read More ›

Avoid wrongly scoped injections with a custom Ninject kernel
I’m currently working on a large project where different teams implement assemblies which are consumed by other teams. We use Ninject for dependency injection: Each assembly has a Ninject module class which registers the available interface-to-implemenation bindings. At the moment, the consumers of these assemblies just know what module classes to load and what interfaces to inject into own objects like ASP.NET controllers or own service objects, but nothing about the scope of the injected objects. Recently we had some nasty runtime errors, because a consumer of one of these assemblies injected a per-request scoped object into a singleton-scoped object. This is why I looked for a way to detect injections of wrongly scoped objects (also known as captive dependencies).
Read More ›

Getting started with Entity Framework Code First Migrations
The following post describes the steps to setup and use Entity Framework Code First Migrations. For more information read this Microsoft page. The sample application shown in this article can be found on GitHub.
Read More ›

How to implement an enum with string values in TypeScript
I currently work an a single-page application (SPA), where we use TypeScript to access web services. In some places, the sent and received data structures use enums to describe the range of allowed values.
Read More ›

Bug Fix: Code Contracts compile error in Visual Studio 2015 and Windows 10
This article shows how to fix Code Contracts compile errors in Visual Studio 2015 and Windows 10.
Read More ›

Avoiding DLL file locks when using .NET reflection in external assemblies
For one of my projects, I had to load external assemblies and query the exported types (i.e. the public classes) using reflection. Everything worked fine, except that the .DLL files were being locked until the application was terminated.
Read More ›

Precompile ASP.NET MVC Razor views in Release mode to find errors at compile time
A problem we often face when developing ASP.NET MVC applications is that errors in Razor views are only detected at runtime while browsing the site. This is because the Razor views are not compiled until they are requested by the browser.
Read More ›

Post-process the HTML output of an action in ASP.NET MVC
This article shows how to implement a post-processor for an ASP.NET MVC application, which transforms the output of an controller action before it is transmitted to the client. The obvious way to do this is by implementing a custom action filter. First, we implement the base filter class:
Read More ›

Manually triggered computed observables in KnockoutJS
In KnockoutJS I sometimes need to create a computed observable which does not automatically detect the dependencies and which has to be triggered manually. This may be required if the computation is very complex and should only run in certain situations.
Read More ›

ASP.NET MVC: How to implement an edit form for an entity with a sortable child collection
This article shows how to implement the edit form for an entity with a collection property. As a show case, we will implement the edit form for a person entity with multiple addresses. The following diagram shows the UML diagram of the two entity classes:
Read More ›

My most used Visual Studio and ReSharper extensions
This article describes some of the Visual Studio and ReSharper extensions and development tools I’m using to enhance my daily C#/.NET development productivity.
Read More ›

Cheat Sheet: Best practices for writing XML documentation in C#
The XML documentation tags of C# are described very well in the MSDN. However, the article does not explain how the contained phrases and sentences should be written. This article tries to fill this gap by providing rules and some sample phrases.
Read More ›

How to implement and register a custom dependency resolver in ASP.NET MVC 5
The ASP.NET MVC 5 framework supports the integration of 3rd party dependency injection frameworks. This can be done by implementing the IDependencyResolver interface and registering an instance of the interface on application startup. The registration is made in the Application_Start method which can be found in the Global.asax.cs file:
Read More ›

Elegant method parameter validation with Code Contracts support
Each C# developer knows the drill: Each method parameter has to be validated against null values, wrong value ranges or other contract constraints. When also validating using Code Contracts, the resulting code may take up most of the method body:
Read More ›

A transparent undo/redo mechanism for XAML applications
In one of my recent projects, I had to implement an undo/redo mechanism for an observable object graph. The usual approach to this problem is to implement commands which operate on the object graph and provide Do() and Undo() methods. The problem was, that a great portion of the business logic was already implemented and was not command-based. This is why I had to find a solution which works transparently on the property change events of an object graph whose objects implement the INotifyCollectionChanged interface and use the ObservableCollection class for collection properties.
Read More ›

Recommendations and best practices for implementing MVVM and XAML/.NET applications
In this article I’ll describe the rules and practices I’m following for XAML and MVVM application development. I’m using the described techniques since multiple years and they have proven themselves for me. Most of the described rules apply for all types of XAML projects – Windows Store, Windows Phone, Silverlight and WPF projects.
Read More ›

How to mimic singlecast events in C#
C# only supports multicast events and delegates. Even if you define a delegate property without the event keyword, it still remains multicasted:
Read More ›

Implementation of “hybrid” (console or GUI) .NET applicatios
Have you ever had the need to use an application (.exe) as a command line tool when started in the console (cmd.exe) and as GUI application when started from the Explorer shell? This article explains a possible implementation for this requirement.
Read More ›

The correct handling of a WCF client’s life cycle
The most intuitive way of handling a generated WCF client’s life cycle is by putting it into a using block:
Read More ›

How to create an MSI installer using the WiX toolset
This article provides a simple guide about how to quickly create a WiX installer project for an existing WPF application or another Windows desktop application.
Read More ›

Taking fear from the .NET/XAML guy: Implement single-page web applications with TypeScript and MVVM
This article provides a simple guide about how to quickly create a WiX installer project for an existing WPF application or another Windows desktop application.
Read More ›

Merging a Pull Request in Visual Studio
Recently I tried to merge a Pull Request from CodePlex directly in Visual Studio. However, if the Pull Request comes from a forked repository, there is no way around using the command line tools to pull the remote branch into a local branch. It is actually very simple; just perform the following steps.
Read More ›

How to compare two methods in Visual Studio
Sometimes I need to compare two methods, for example to check if they can be refactored into one. To avoid the time consuming step of copying the two methods into separate files and compare them, I recommend using the Visual Studio extension ClipboardDiff.
Read More ›

Write detailed C# XML documentation and still keep the source code clean
For my open-source project MyToolkit I write a lot of documentation. Currently the documentation for a class has to be updated in two locations: The source code and the project’s wiki. I asked myself how to avoid this and document everything in the source code file – while keeping the source code simple by not putting too much documentation in it.
Read More ›

Use JSON files with schema for application configuration
Often, we face the problem that our customers need highly configurable applications but there is no time to develop rich configuration GUIs. This article describes a possible solution which is a compromise between editing raw configuration files and implementing rich configuration GUIs.
Read More ›

Use XBMC and other non-certified PlayTo receivers in Windows 8
PlayTo is a great technology which provides the ability to play the current video or music from your tablet to your TV. The problem is, that most devices, for example a HTPC running XBMC, supports PlayTo but is not certified. However there is a way to simply disable this restriction and use non-certified devices as PlayTo receivers. The reason why this is not enabled by default is that these devices may not work properly.
Read More ›

Develop an app which targets WP7 and WP8 (and WinRT) at the same time
This post shows how to develop an app which targets the WP7 and WP8 platform at the same time. The idea is to create two projects – one for WP7 and one for WP8 – and link all files into one of the projects. This way you don’t have to maintain the code twice and only have to develop in one project. On Microsofts website you can find the base idea. However this article shows even more problems and their solutions when using this approach. Here are the steps to setup the solution:
Read More ›

EF & WCF: Serialize not loaded collection navigation properties as null rather than an empty collection
Sometimes a web service client wants to know if a collection navigation property (a navigation property with “many” references) of a received entity object has been loaded on the server (e.g. by using Entity Framework’s Include method). By default, not loaded collection navigation properties are serialized as empty collections (not null). This is why the client cannot differentiate between a not loaded property and an empty collection. In one of my projects, I needed to have this information to know if a property is already loaded or has to be lazy loaded using an additional web service call.
Read More ›

Sketchagram diagram editor for Windows 8 released
The first version of Sketchagram has been released to the Windows 8 App Store.
Read More ›

WinRT: Access string resources in a stongly typed way (C#)
In WinRT/C# projects the .resx resource file is not available anymore. The new resource type is .resw which is directly supported by the XAML framework. The drawback of this new file format is that it does not automatically generate a code-behind C# class with a property for each key-value resource pair. The problem is that it is not possible to access these strings in a strongly typed manner. The only way to load resource strings is to load them by specifying the resource key as a string. The problem with this solution is that typing errors are not detected by the compiler but on application runtime.
Read More ›

WinRT: Navigate to the previous page by pressing the back key
If you are developing Metro applications, it is evident to not only have a good tablet experience but also a a good desktop (mouse and keyboard) experience. This is why I implemented a simple solution to navigate to the previous page if the user presses the back key. A lot of standard applications in Windows 8 support this feature already and I hope a lot of new applications will support it as well.
Read More ›

Using Entity Framework Code-First proxies with WCF web services
This blog post demonstrates how to set up a WCF web service together with lazy loading Entity Framework entities. The entities will be developed using a code first approach and their metadata is defined using the fluent API. To use all these features you need to install the newest Entity Framework (version 4.3.1 as of now) as a NuGet package (search for “Entity Framework“).
Read More ›

Implement secure WCF web services to use with Windows Phone and Metro style apps
The first part of this blog post demonstrates how to implement a WCF web service with username/password authentication and role based authorization. The web service can be used in Windows Phone applications and Windows 8 applications and it is even possible to use it with other libraries or frameworks. The second part explains how to set up the development environment to test the web service and the client application locally.
Read More ›

XBMC remote for Windows Phone
I’d like to introduce my XBMC remote app for Windows Phone: It is called “XBMC remote” and can be downloaded from the Windows Phone Marketplace. XBMC is a media center software designed to use with a TV and can be downloaded and used for free. The application only works with the newest XBMC release, XBMC 11 Eden. With the “XBMC remote” app you can browse your recently added media, albums, artists, music videos, movies and TV series:
Read More ›

Jumpy ListBox while scrolling in Windows Phone 7.5
I recently discovered a bug in the ListBox control for Windows Phone 7.5. In a long list of items (virtualizing list, items with different heights), the list sometimes begins to get jumpy and the list cannot be scrolled to the end. To reproduce the problem, open a long list of items, scroll a little bit, stop the scrolling and tap on an item. Now if you start scrolling again the list begins to get jumpy…
Read More ›

Create Task-based method from “legacy” callback method
In my projects I have a lot of asynchronous methods with a callback as parameter which is called when the operation has completed. I asked myself how to port these methods to support the new async / await keywords and if possible allow me to use the class with older frameworks which do not support this new functionality. The samples in this article use the Http classes from my library project MyToolkit.
Read More ›

Retrieve Entity Framework DbContext from a proxy object
There are some situations where you need to get the DbContext from a proxy object generated by the Entity Framework (current version: 4.5). Every generated proxy object holds a reference to the ObjectContext it belongs to. The problem is, that the ObjectContext does not have any information or reference to the corresponding DbContext. My solution is to maintain a static list with a ObjectContext-DbContext-Mapping:
Read More ›

Reusable page transition animations in Windows Phone 7/8 Silverlight
I searched a while finding a simple solution to add transition animations for my Windows Phone 7 application.
Read More ›

Transactions in the Entity Framework
First, I’ll show an example of the correct usage of an Entity Framework’s ObjectContext. At the beginning of the usage block, the ObjectContext is created; at the end it will be disposed (see using-Keyword).
Read More ›

Interceptors with PHP
Interceptors are used for aspect oriented programming (AOP). With the given interceptor, method calls can be extended or suppressed. PHP interceptors are implemented using the _call magic method.
Read More ›

Event-based XML parsing in Java
On some inefficient devices or some programming languages there are only event-based XML parsers available. In this article I will show how to use such a parser in an easy way and how to read hierarchical XML structures.
Read More ›