Wix Toolset – custom action to preserve connection string on upgrade

In my previous post I showed you a standard template of WiX installer. Today you will see how to add a custom action to the installer so you can perform more customized operations during the application installation process. The custom action, which I am going to present in this post, will expose a method that extracts the value of specific node of provided xml file. The action…

By Mirek on (tags: Installer, WiX, categories: code)

Version tolerant XML Serialization

One of the beauties of xml, is that it can be extended without breaking applications. You can add element to the xml document tree and the application should not crash or fail while consuming this xml. This is what we can read on the w3schools.com xml tutorial. But how is this with serialization of the xml? Recently I found a guide on MSDN which is called Version Tolerant Seria…

By Mirek on (tags: Version Tolerant Serialization, XML, categories: architecture, code)

Mapping XML column with XSD schema validation in EF Code First

The XML data type allows storing a xml content in our SQL Server database. The great feature is that we can also attach an XSD schema to it and have the xml content automatically validated. Here I am going to show you how to set it up together with Entity Framework Code First. Storing XSD Schema in database and mapping entity One could ask: what is the point of validating the x…

By Mirek on (tags: Entity Framework, SQL Server, XML, XSD, categories: architecture, code)

InitialCreate migration and why is it important

Entity Framework migrations is indeed a great feature. It makes you don’t need to worry about the database schema updates almost at all. There are however few things you must know to properly understand and use EF migrations. This post describes few of those things. Usually when you start a new project which makes use of Entity Framework and you starts developing it with a defa…

By Mirek on (tags: Entity Framework, migrations, categories: architecture, tools, code)

Movable rows in WPF DataGrid

DataGrid control in WPF is a rich table structured control, which is perfect for displaying any kind of data in table like format. The one think about DataGrid it always lack, is a possibility to easily change the order of rows. It is not even about drag and drop of rows and items from and into the DataGrid , but simply rearrange existing rows in DataGrid control. It this post …

By Mirek on (tags: Attached property, DataGrid, WPF, categories: code)

Web Api: custom binding with AutoMapper

In Web Api 2.0 and MVC5 you can only pass: int, bool, double etc.., TimeSpan, DateTime, Guid, decimal, and string values in URI. For any complex type having lists or other complex object within you have to pass serialized JSON/XML in the request body. But what If we want use such complex type from URI? Then read on… What is binding? Binding is a mechanism used by the Web Api to…

By Piotr on (tags: automapper, mvc, Web API, categories: code)

MVC custom error pages

Long story short – mvc does not handle custom error pages in a way that could be described as ‘even close to correct’. But if you need to fulfill a requirement, you start hacking. First of all, I’d like to share a few links: http://www.prideparrot.com/blog/archive/2012/5/exception_handling_in_asp_net_mvc http://benfoster.io/blog/aspnet-mvc-custom-error-pages http://www.secretge…

By on (tags: mvc, categories: code, web)

Nested foreach loops replacement in C#

Nested foreach loops is something that I have always felt uncomfortable with. Recently I have found out more elegant and in some cases even more efficient, replacement for nested double foreach loop. Lets assume we have two lists of strings filled with some values and we want to have a collection of all combinations of elements from list l1with elements from list l2. Obvious so…

By Mirek on (tags: c#, Join, categories: code)

WPF CollectionView can leak memory

A time ago I wrote about using collection views in WPF to achieve different looks at the same source collection. By creating different instances of ListCollectionView we could have the collection displayed in different sorting, ordering and grouping shape. Unfortunately there is small trap when using collection views. CollectionView class instantiated with a source collection t…

By Mirek on (tags: CollectionView, memory leak, WPF, categories: code)

Memory leak by misusing Autofac

Recently I’ve found out that we can easily cause a memory leaks in our .net application by improper usage of the dependency injection container Autofac. The case of this problem concerns only components that implements IDisposable interface, so are meant to handle some unmanaged resources and need to be disposed when no longer needed. Let me show you how to reproduce this probl…

By Mirek on (tags: Autofac, IDisposable, memory leak, categories: code)