C# WPF Generate and Display QR Code

Download QrCode.Net

Download and install QrCode.Net from NuGet, there are two ways to install it.

Right click your project, select Manage NuGet Packages, in newly opened NuGet Package Manager tab, choose Browse tab and type QrCode.Net in Search text box, and install the QrCode.Net package by clicking the download icon at right side.

Or

Run following command in Package Manager Console

 

Create Container Window

Create a window with name MainWindow and add an Image control named QrCodeImage into it.

MainWindow.xaml

 

Display QR Code in Window

In MainWindow.xaml.cs MainWindow constructor function, add following code (should be located after InitializeComponent() method)

 

Running the project you will see the QR Code is displayed in the MainWindow.

 

 

RavenDB NotSupportedException

When I run the code

 

I got following exception

RavenDB NotSupportedException

An exception of type ‘System.NotSupportedException’ occurred in Raven.Client.Lightweight.dll but was not handled in user code

Additional information: Could not understand expression: .Where(p => p.ProductSn.Contains(value(YSPOS.MainWindow+<>c__DisplayClass10_0).barCode))

 

It’s because there is no index for ProductSn attribute is created.

 

Solution

To fix this issue, we need create index fo ProductSn attribute.

 

Create a class extending AbstractIndexCreationTask class

 

Then execute this index creation task after DocumentStore initialization.