Repository navigation
Description
This issue is intended to initiate version 2.0 of the QRCoder. I would like to see an active discussion here so that we can shape the implementation of version 2.0 together. Feedback from the community is very important to me.
Why QRCoder 2.0?
The current version of the QRCoder is essentially still based on the first developments from 2013. Although the QRCoder has been repeatedly adapted to the times, large parts are still based on System.Drawing.Common, which since .NET 6.0 has only been supported under Windows.
Since then, this has often led to confusion, as parts of the QRcoder have only been available under Windows since .NET 6.0, which despite I wrote an Wiki entry is far from obvious to all users.
Although there have already been some PRs and suggestions for version 2.0 in the past, I have shied away from adopting the vision of individual contributors without consulting the community. I want to make up for this with this issue.
Version 2.0 should first and foremost provide clarity and create a consistent interface that is available on as many platforms as possible. Since this most likely means turning away from System.Drawing(.Common) and thus requires breaking changes, this release will be merged into a new major version (2.0).
Requirements for QRCoder 2.0
- The QRCoder should work on as many platforms as possible (at least near full support under Windows and Linux)
- If a component is only available on one platform, this should be clearly recognizable and comprehensible for the user
What needs to be clarified?
In order for the implementation of version 2.0 to be a success (both in terms of the result and the path to it), a few decisions need to be made in advance. Here I am hoping for feedback from you, the community.
(To keep things clear and simple, please give feedback in the dedicated issues, linked below).
- [WIP] How do we split the QRCoder? (NuGet packages) #540
- [WIP/QRCoder2] How do we split the QRCoder? (Github repositories) #541
- [WIP/QRCoder2] Version number handling #542
- [WIP/QRCoder2] Documentation and wiki #543
- [WIP/QRCoder2] How do we handle changes during the 2.0 development? #544
- [WIP/QRCoder2] Coordination of development (VCS) #545
- [WIP/QRCoder2] Coordination of development (Organization) #546
- [WIP/QRCoder2] Communication tools besides Github? #547
- [WIP/QRCoder2] System.Drawing vs X #548
- [WIP/QRCoder2] Use of System.Drawing.Primitives #549
- [WIP/QRCoder2] How do deal with COM-support? #550
- [WIP/QRCoder2] Shall we re-think the Payload Generator? #551
- [WIP/QRCoder2] Consider Removing QRCodeGenerator Instance Methods #552
- [WIP/QRCoder2] Which frameworks and language version to target #553
- [WIP/QRCoder2] Consider Removing Nested Types from Public API Signatures #555
- [WIP/QRCoder2] Consider Updated Abstractions #557
What else is missing from this list? Do you have any other points? Let us know!
Which issues / PRs does the QRCoder 2.0 solve?
As mentioned, there have already been some issues and PRs in connection with a version 2.0 or the replacement of System.Drawing.Common. I would like to list the ones (that are still open) here in order to track which problems we can solve with the 2.0 release.
PRs
Issues
- Consider a Streamlined/Slimmed-down Version 2.0 #242
- System.Drawing.Common version conflict #308
- System.Drawing.Common is deprecated on non-Windows platforms #315
- QRCode class is not visible on net6.0 targeted web app projects #366
- Type or namespace "QRCode" could not be found in new Blazor Server .Net 6 App #377
- .NET 6.0 Compilation Error: The type or namespace name 'QRCode' does not exist in the namespace 'QRCoder' #382
- The type initializer for 'Gdip' threw an exception. #389
- .NET 6.0 - TypeLoadException #393
QRCodeis not found in .NET 7 #435- QRCode' does not contain a definition for 'GetGraphic' and no accessible extension method 'GetGraphic' accepting a first argument of type 'QRCode' could be found #441
- QRCode namespace doesn't exist in .NET 6+ #489
Support
To get the discussion started, I would like to mention some of the contributors who have worked on the QRCoder in the past. I hope I can count on your valuable feedback once again:
@Shane32, @csturm83, @mishfit, @iamartyom, @abdoutech93, @DevonJSmith, @jnyrup, @nayuki, @alexnsfx, @sbrickey, @strawberryfield, @giccifelipe, @gfoidl, @oheim, @SteveGTR, @PolnerA, @MarkusG, @pontusi, @Timwi, @maartenba, @JimmyPun610, @AntonKorn, @emorell96, @natehitze, @cezar-pimentel, @codeputer
Activity
codebude commentedon May 1, 2024
This second post serves as a placeholder to record decisions/results that we have made as a community for version 2.0.
For version 2.0 of the QRCoder we have decided on the following:
New feature that we want to implement in QRCoder 2:
Things that were discussed for QRCoder 2, but made it to production before
v1.6.0)v1.6.0)Shane32 commentedon May 2, 2024
Thanks @codebude for all the effort on this project and seeking the advice of the community here! Below I provide my suggestions and reasoning:
I suggest that all code that can operate with "pure .NET" code should be in the main package. This would include the generation code along with SVG, PNG and other common output formats that do not rely on external dependencies. Now that trimming is available with .NET 6+, and NativeAOT in .NET 8, splitting the project into smaller pieces just makes the project more difficult to use.
See item 3 below.
I think these questions 2 and 3 are the same. If all NuGet packages are released together, having a single repository makes testing and publishing much easier. Most specifically if they are separate, then it's a real pain to utilize unreleased features in dependent repositories. Rather, you have to release the parent package, then test and update the dependent packages, then release them, hoping that you didn't miss something and have to go back and change the parent package. Having a single repository ensures that all tests are run on the same unified version of QRCoder.
As for versioning, I think we can learn from MS's example, where with .NET Core 3.x and prior, each package had unique versioning, and with .NET 5+ every package has the same version number. Having the same version number for all related packages makes it very easy for a developer to identify which version is the latest, and which version was tested with what dependency.
As a practical example why this is useful, if you pull a 'child' package, say QRCoder.SkiaSharp, and then an update is pushed for the base QRCoder library, developers will see an update to QRCoder.SkiaSharp and pull it, whereas if each package had individual versioning, they would not know that QRCoder had an update without specifically checking. And then to pull it now they would have two references in their project file.
This issue occurs today with ASP.NET Core 2.1 applications running on .NET Framework 4.8 (a still-supported scenario), where all user-referenced dependencies are up-to-date, but yet some of the indirectly referenced dependencies are out of date, and worse, have a security-related flaw. This rarely happens with .NET 5+ where most packages are released together, each version referencing the same version of its dependencies.
I don't have a great suggestion here. At GraphQL.NET the documentation is stored within the main repository, and published automatically upon merge to a separate website; we do not use the wiki. It allows any contributor to suggest a change via PR, while providing for review by maintainers. It also keeps the documentation tied to a specific version/commit. It's most beneficial when working on new versions or features, as it allows contributors to update the documentation alongside their feature changes. Maintainers can request that contributors update the necessary documentation before merging the PR. However, we currently have no way of allowing users to view old documentation (besides browsing the repository at a old version).
I would suggest that the readme file be maintained and the same file be published in the NuGet package, rather than two separate readme. For the GraphQL.NET Server repository, all the documentation is in the readme file, and as such it is all available on NuGet for any version. If the amount of documentation in aggregate is sufficiently small, then this works well, I believe.
I think the answer depends on the quantity of breaking changes (and ease of developers to upgrade). Due to the popularity of the QRCoder project (27 million downloads and counting), I personally would attempt to release 2.0 with only removal of System.Drawing dependencies, as 1.4.3 and newer do not contain these missing classes anyway. Essentially, I would attempt to have version 2.0 be 100% backwards compatible for the
net6.0tfm. If that was the case, I think there is no reason to continue development on 1.x.On the other hand, if a complete rewrite of the exposed API is desired, then I would maintain bugfixes for 1.x if/when requested by a contributor. It is quite easy to set up GitHub to allow for this. At GraphQL.NET we can easily release bugfixes for old versions if needed, although we very rarely receive a request to do so; typically users need help upgrading if anything. Having excellent migration documentation really helps in these cases.
I typically push new major version changes into a
developbranch, keepingmasterfor the current major version. Inevitably bug fixes come up before the next major version is ready, and then it is easy to push these changes intomasterwhile still continuing to develop v2. Also, it allows backwards-compatible features to be pushed into v1 while also being merged into v2. A good example would be the performance improvements PR #509 . If we had been adding SkiaSharp functionality into the master branch, then it would not be possible to push performance improvements into v1. Typically at GraphQL.NET when we release a new major version, I simultaneously release the last version of the current/prior major version alongside the new major version; then I mergedevelopintomasterand continue onmaster.I believe this question may be more applicable when there is a larger development team. But in general, I'd suggest that contributors just review goals in a GitHub issue before spending a lot of time on a PR.
I don't think it's necessary. Having all questions posted publicly is likely preferred for an open-source project. Perhaps we just open an issue for v2 and keep it open to track features and ask questions, etc.
I suggest maintaining the existing code. While it's usefulness is likely declining, I see no reason to pitch the existing code. It will certainly be useful for existing users that wish to upgrade to 2.x, and serves as a template (if we like the design pattern) for SkiaSharp / ImageSharp / etc.
I suggest 'whatever contributors wish to offer PRs for'. Ideally:
Compare to ZXing.Net which has these NuGet packages available:
I would use System.Drawing.Primitives if/as desired, as it creates no dependencies except when targeting .NET Standard 1.3.
Framework targets
For QRCoder 2.x, I would target no less than .NET Standard 2.0. This is in line with Microsoft's example (most of their libraries are still .NET Standard 2.0 compatible) and their stated recommendation:
https://learn.microsoft.com/en-us/dotnet/standard/net-standard#when-to-target-net80-vs-netstandard
Having a target of .NET Standard 2.0 as a minimum allows near-maximum compatibility with both .NET Framework and other targets, such as the Wilderness Labs Meadow F7 system-on-a-module (which now runs .NET Standard 2.1 code).
I would also have a minimum of testing for currently supported and the last couple unsupported LTS versions of .NET. For instance: .NET Framework, .NET Core 3.1, .NET 6.0, .NET 7.0, .NET 8.0.
Personally I would retain compatibility with older frameworks, until if/when we run into problems developing. For instance, if the next version of Visual Studio cannot compile for .NET Framework 3.5, then I would drop it. QRCoder v1.x works well and can be used for .NET Framework 3.5. I also would be fine dropping testing on these older frameworks.
I also would be fine dropping testing on platforms that do not have a compilation target. As an example, if .NET Core 2.1 and 3.1 both use the same .NET Standard 2.0 compilation target/output, we really shouldn't need to test on both platforms. But if it's easy to test on more platforms, it doesn't cost anything, so why not?
I would mark the assembly as trimmable and add some very basic testing for NativeAOT, if we can. This should require almost no effort (as the project does not use reflection) and allows for QR codes to be generated on NativeAOT compilation targets, webassembly / Blazor, and so on.
Dependencies
I think it would be ideal if the base NuGet package (with outputs for svg/png/ascii) had zero dependencies. However, the character encoding may require System.Text.Encoding.CodePages. Specifically, the ISO-8859-2 character encoding (non-default) is not included natively with .NET and relies on underlying system support. Also the Russian payment method generator relies on a user-determined code page. There are a few ways to handle this issue:
See: https://learn.microsoft.com/en-us/dotnet/fundamentals/runtime-libraries/system-text-encoding
Commits
I suggest using 'squash and merge' to merge PRs in, and require PRs for all commits. This makes the commit history of the main branch very easy to follow. I would suggest that any time master is merged into develop, or vice versa, a standard merge commit is performed. This allows easy and accurate tracking of the state of the code in the master and develop branches at any point in time. With regular merge commits, it is very difficult to follow the progression of the code. Compare the difference:
https://github.com/codebude/QRCoder/commits/master/
https://github.com/graphql-dotnet/graphql-dotnet/commits/master/
In the latter example, each commit contains exactly to the final changes of a merged PR.
I also typically configure the "default commit message" to be "pull request title". Without this change, the default message when there's only a single commit is the commit title. When the commit is ill-named (e.g. "Updates"), this is an issue. But when using the pull request title, it greatly reduces the frequency of an ill-named commit in the commit history.
Debugging
I suggest embedding debug information into the compilation. While the NuGet download is slightly larger, it does not affect execution speed, nor does it affect the size of trimmed applications. The benefit is that developers can right-click any member and 'peek' to instantly view the exact original source code of QRCoder from within Visual Studio.
C# Language version
I suggest upgrading to the latest C# language features via
<LangVersion>latest</LangVersion>. This means that we need to be careful to not to use features like init-only properties which will break older targets. But some things like file-scoped namespaces are very nice to use and do not change the compiled code at all.Shane32 commentedon May 2, 2024
New feature suggestions
digitaldirk commentedon May 2, 2024
4. Documentation and wiki:
I would love to have a documentation site that is interactive. A Blazor wasm project that could be in this repo or seperate if wanted. I would be happy to contribute towards this. I have made a few webites/pages that allow for QR code customization using Blazor. I personally find Github's wiki a little lacking.
MudBlazor as an example:
https://mudblazor.com/components/slider
https://github.com/MudBlazor/MudBlazor
Depending on how 2.0 shapes out some documentation maybe could not be interactive but could still be in the same docs project.
Here is a rough idea for a demo (This is using MudBlazor, ImageSharp, QRCoder):
InteractiveQRDemo.webm
csturm83 commentedon May 4, 2024
My vote would be to clean up the public API and better organize the structure of the main project. Maybe have separate namespaces for the core logic, for payloads and for renderers at least (for better discoverability).
At present there are at least a few ways to create a QR Code. There are
QrCodeGenerator.CreateQrCodeinstance methods (1) which delegate to theQrCodeGenerator.GenerateQrCodestatic method (2), and then there are also theGetQrCodestatic helper methods (3). Maybe just pick one preferred way moving forward?That said, I had also been experimenting with a more fluent-like extension method approach:
Usage:
There would be some factoring out of
IDisposableneeded to make it work.Not sure why theI also wasn't sure of the value ofMemoryStreaminPngByteQRCodeneeds to be a class variable. Seems as though theMemoryStreamlifetime could be managed in theGetGraphicsmethods (plumbing theStreamthrough the helper methods).Disposefunctionality inQRCodeData? Maybe @codebude could clarify if it could be removed.Edit: Disregard the bit about the
MemoryStreamimplementation inPngByteQRCode. I was looking at thePngBuilderIDisposableimplementation by mistake. All*QrCodeimplementations implementIDisposableby way ofAbstractQrCode'sDisposemethod, which simply disposes theQRCodeData.Here is
QRCodeData.Dispose(not actually releasing unmanaged resources, just setting to default values):Other random thoughts:
GetGraphicstoRender?RenderOptionsorRenderSettingsto clean up some of the parameter lists that have gotten a bit unwieldy.AbstractQRCodeto enforce a minimal contract for all subclasses. E.g.Render(RenderOptions options)csturm83 commentedon May 14, 2024
My thoughts on Question 1, how to split NuGet packages:
Original QRCoder package stays v1.x. I feel that keeping the same package name for v2 would be a landmine for folks blindly upgrading and complaining about things being broken. An updated NuGet package Readme and prominent documentation can point them to new v2.0 packages.
New Packages (v2.x):
Renderer and Payload packages would have a dependency on abstractions defined in the Core package. The thought is that it would be pay for play. If you want to bring your own renderer to the game, you don't have to bring in anything other than the Core package as a dependency. Just supply an implementation for the abstractions defined in the Core package.
csturm83 commentedon May 14, 2024
Regarding the core abstraction for Renderers, this commit removed the genericity of
AbstractQrCode(renderers) to support COM.In my opinion, something like the original abstraction would be preferable. Is COM support a MUST in v2.0? If so, can it be supported in some other way without limiting the design?
Shane32 commentedon May 14, 2024
I suggest removing COM support
csturm83 commentedon May 18, 2024
I have been working on a prototype branch. Most things are still unimplemented (a matter of migrating over and cleaning up existing code). I had just been focusing on the project structure/organization and public API changes. I would also wait for performance PRs to land before migrating over the core QR generation code.
If anyone's interested, the
QRCoder.Core,QRCoder.PayloadsandQRCoder.Renderersprojects in that branch contain the beginnings of a proposed project structure and public API (detailed a bit above). Throwing it out there for feedback or suggestions.@codebude
Shane32 commentedon May 18, 2024
I was thinking about the
Payloadclass. Currently there are options for:Does a payload ever need to specify a specific size (version), ECC mode or Eci mode? They are never overridden. Seems like logically these are just encoding details and not "payload", and as such perhaps it would make more sense for those options to be specified during generation, and not be part of the
Payloadclass.codebude commentedon May 18, 2024
Hi @Shane32
You are wrong this time. The
SlovenianUpnQrpayload generator uses this feature. See: https://github.com/codebude/QRCoder/blob/master/QRCoder/PayloadGenerator.cs#L2382The values from the payload are used in the corresponding
CreateQrCodeoverload in theQRCodeGenerator. See: https://github.com/codebude/QRCoder/blob/master/QRCoder/QRCodeGenerator.cs#L42The idea behind the payload generators is to make it as easy as possible for users to create a QR code according to a given specification. Sometimes the specifications also contain requirements for version or ECC level. In fact, this is not only the case for the SlovenianUpnQr, but also for the following payload generators:
I opened an issue for this techincal debt:
Shane32 commentedon May 18, 2024
Got it. Perhaps then these settings inside the payload class should be like constraints? Perhaps an exception is thrown if trying to generate a QR code that conflicts with a constraint?
codebude commentedon May 18, 2024
If it were only up to me, we could happily remove COM support. However, I fear that the feature will be used more than expected. As part of the SwissQRCode, I have received a number of requests asking if I could help integrate the generator into Excel or Access via COM. (Due to lack of time and confidence in my COM skills, I have never done this for 3rd parties - but I suspect that some others have.) I would hate to offend these users.
If there is a way (additional wrapper library, etc.) to make the QRCoder usable in COM environments and at the same time get rid of the current implementation, then we can throw away the current support. (Otherwise we propably would have to continue to support the 1 version at least in terms of payload generator updates).
12 remaining items
csturm83 commentedon May 26, 2024
For reference, here is recent MS guidance.
codebude commentedon May 27, 2024
@csturm83 I carved out the target framework discussion into this issue: #553 and linked it (as also as your issue from yesterday) in the first post.
codebude commentedon May 31, 2024
To be honest, I've never thought about it before or actively decided to use squash and merge instead of merge commits. But I've read up on it a bit and yes, we should try it out. For now, I have implemented the settings as suggested by the .
I had already implemented this rule a few weeks ago.
codebude commentedon Jun 2, 2024
Hi @csturm83 @Shane32 ,
the discussions of the various topics are in full swing. However, I'm pretty sure we won't get all the issues from the first post resolved before we start implementing v2. (You are already submitted PRs related to v2 in the meantime).
Therefore the following suggestion for the further procedure. I would like to finalize and merge the following three PRs:
Then I release the current code as v1.6.0 and publish the Nuget packages. I would then create a
develop/v2branch from the master in which we start development for v2. I would then stop any further changes to v1 (unless they are security-relevant).We can continue to use this issue here (especially the first two posts) to track the development and the things that still need to be clarified. Is that a viable option for you?
Shane32 commentedon Jun 2, 2024
Before starting any work on v2, I would like to add another PR (after the above PRs are merged) that will:
dotnet formatto match editorconfig, and complete any non-automatic formatting requirementsSecondly, I'd like to do some XUnit cleanup:
[Category]attributes which have no effect todayMy goal over these last few PRs is to get the current v1 code cleaned up nicely so we have a good codebase from which to kick-off version 2, and enforce upon ourselves good coding practices and a high degree of quality for our new code.
I would like to add one last optimization which I think will have a considerable effect, which is to interleave the ECC data to the output stream simultaneously while calculating it. Benchmarks indicate that this is currently a considerable bottleneck of the performance, however, this isn't easy to do, and the current implementation is 'fast enough'. We don't need this to make it in v1.x.
Shane32 commentedon Jun 2, 2024
By the way, if publishing to NuGet requires some effort, I can assist automating this. In GraphQL.NET, all you have to do is issue a GitHub 'release', and it will publish to NuGet automatically with the version number specified by the tag in the release. This makes it very easy to either issue new releases or issue security fixes for older versions.
csturm83 commentedon Jun 2, 2024
@Shane32 would you recommend treating warnings as errors?
Shane32 commentedon Jun 2, 2024
Yes
codebude commentedon Jun 2, 2024
Ok, then I'll wait for the PRs before publishing the 1.6.
From what I've read it still should be possible to use categories/traits. In Visual Studio Test Explorer (see nunit/nunit3-vs-adapter#639 (comment)) as also as in dotnet test (see https://stackoverflow.com/a/42287012/251719). I guess it's just our CategoryDiscoverer and Attribute class which seems to be broken. But since we always run all the tests anyway, we can do without the attributes and remove them. I just wanted to make it clear that it still seems theoretically possible to use them.
It's not a lot of work. I have a small shell script that downloads the nupkg from the Github package builds. I then upload it via the nuget.org web interface. All in all, maybe 2 minutes of work. For the fact that there is only one release every now and then, that's enough and I don't see a need to automate it.
HuaFangYun commentedon Aug 9, 2024
I would like to know when 2.0 will be released, thank you!
fabianoriccardi commentedon Apr 4, 2025
Will you add Micro QR Codes in v2?
Shane32 commentedon Apr 13, 2025
It could be added in the current version.
Progress: