Skip to content

Generate QR Codes With QRCoder: .NET 10, QRCoder 1.8.0, SVG renderer - #2279

Open
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/116655-aspnetcore-generate-qr-codes-with-qrcoder
Open

vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/116655-aspnetcore-generate-qr-codes-with-qrcoder

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Article: https://code-maze.com/aspnetcore-generate-qr-codes-with-qrcoder/

Updates the QRCoder sample for the article refresh. Only dotnet-client-libraries/QRCoder changes.

  • Both projects move from net8.0 to net10.0.
  • QRCoder 1.4.1 to 1.8.0.
  • GeneratePng() renders black on white again with GetGraphic(20), which is what the article's first screenshots show. The red on dark blue call moves to a separate GeneratePngBranded() method with its own "Branded" entry, which the article's Colors section points at.
  • New GenerateQRCodeSvg() method and "SVG" entry, rendering the same text with SvgQRCode as a data:image/svg+xml URI.
  • QrCodesDb is registered as a singleton, so its store becomes a ConcurrentDictionary<string, byte[]> and Add uses TryAdd (no ContainsKey plus Add race).
  • @model HomeModel; loses the stray semicolon.
  • Program.cs uses MapStaticAssets() and .WithStaticAssets() like the .NET 10 MVC template, in place of UseStaticFiles().
  • Tests: the existing test checks the six keys; two new tests check that the PNG output starts with the PNG signature bytes and that the SVG output is an SVG document.

No using was added to any CreateQrCode() result: disposing the renderer already disposes the QRCodeData it was given.

Package versions, re-queried on NuGet on 2026-10-10 (latest stable):

  • QRCoder 1.8.0
  • Microsoft.NET.Test.Sdk 18.10.1
  • xunit 2.9.3
  • xunit.runner.visualstudio 4.0.1
  • coverlet.collector 10.1.0

Local run on SDK 10.0.302, runtime 10.0.10: build 0 warnings and 0 errors, 3 of 3 tests passed, dotnet list package --vulnerable --include-transitive clean on both projects. The app was run and all six images decoded in a browser.

Retarget both projects to net10.0 and bump QRCoder to 1.8.0 and the test
packages. GeneratePng renders black on white again; the coloured call
moves to GeneratePngBranded. Add GenerateQRCodeSvg with SvgQRCode.
QrCodesDb uses ConcurrentDictionary with TryAdd. Drop the stray semicolon
on @model, switch to MapStaticAssets, and add PNG and SVG output tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant