QR Barcode - incorrect version number

Hello. I’m trying to generate 2 QR codes with the same amount of characters the only difference is actual characters. When I am using all settings as auto I am receiving one QR as Version07 (45x45) and another - Version08 (49x49). This is an issue for us as we use predefined amount of characters and expect only 45x45 due to envelope size and other formatting requirements.

Having Version07 set manually in the builder configuration results in error for the second QR which is “QR Barcode - incorrect version number”. This is kind of frustrating because amount of characters is identical.

Here is the code I’m using:

using (var barcodeStream = new MemoryStream())
{
    var barcodeBuilder = new BarcodeGenerator(EncodeTypes.QR, id)
    {
        Parameters =
        {
            Barcode =
            {
                QR = { QrVersion = QRVersion.Version07 }, 
                CodeTextParameters = { Location = CodeLocation.None }
            }
        }
    };

    barcodeBuilder.Save(barcodeStream, BarCodeImageFormat.Png);
    return barcodeStream.ToArray();
}

Data that is used:

QR1: 0d2dc3f2-f5a8-4cae-9ca3-cd2e11b7e27b_56ba6a61-926b-4810-ac4d-a1cd57a9469a_                              _LOYOLA MARYMOUNT UNIVERSITY             _9926349
QR2: 0d2dc3f2-f5a8-4cae-9ca3-cd2e11b7e27b_6a0ce2fb-046c-46a5-8344-e23e2ace71c0_                              _LP Consulting Engineers Inc.            _9911323

Can you please help me to resolve this issue?
This is C#, library Aspose.BarCode and version number 21.4.0.

Digits and symbols have different encoding size in QR. QR tries to encode data to minimal size, but you can set required version manually.

So 4810 and 46a5 has different size.

So that is what I was trying to do, in my code sample I am setting required version QRVersion.Version07 manually but receiving “QR Barcode - incorrect version number” on second QR generation. Am I doing something wrong?

If QR code cannot fit to current version the engine throws exception. But you can generate all codes in 49x49 size or larger.

About encoding sizes:
ISOIEC 18004_2006Cor 1_2009.pdf (1.2 MB)

ISO/IEC 18004 QR Code 2005 bar code symbology specification
6.4.3 Numeric mode
6.4.4 Alphanumeric mode
6.4.5 Byte mode

Also you can encode data in Byte mode, in this way all symbols will be encoded as 8 bit pattern without any data compactification.

BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.QR, "12345");
generator.Parameters.Barcode.QR.QrEncodeMode = QREncodeMode.Bytes;
generator.Save(@"d:\save\rec\this.bmp", BarCodeImageFormat.Png);

Thanks for the response, Alexander.
I tried to use QREncodeMode.Bytes and as a result library defaults qr version to Version08 if you do not set version on your own and you get both 49x49. If you do (I need to use Version07, 45x45) it crashes on the same error QR Barcode - incorrect version number even on the first QR which normally generates as 45x45 without issues.

I can go to any online QR generator, like this for example Free Online QR Code Maker - QR Code Generator and successfully generate both QRs as Version07 (45x45) using QR data from my first post. No issues. Even if I specify version as auto it will anyway generate both as Version07 (45x45). I am trying to understand what I am missing here with the Aspose library, is it possible there is a bug in it?

Thank you, currently I see bug and will investigate our compactification algorithm (there could be some differences from standard). I set investigation task on this week.

Thank you, Alexander. Looking forward to hear about the progress and hope it will be an easy fix.

TestVersion.zip (3.2 KB)
qr1.png (2.9 KB)
qr2.png (2.9 KB)

I tested both codetexts and both on them are generated with correct Version 7 size. TestVersion is test project for VS2019/2017.

Alexander, thank you for your example. My apologies, I missed one adjustment to the codetext in our code that adds trailing spaces to the end of it to match our standard 166 character length format.

These are now correct codetexts:

QR1: 0d2dc3f2-f5a8-4cae-9ca3-cd2e11b7e27b_56ba6a61-926b-4810-ac4d-a1cd57a9469a_                              _LOYOLA MARYMOUNT UNIVERSITY             _9926349             
QR2: 0d2dc3f2-f5a8-4cae-9ca3-cd2e11b7e27b_6a0ce2fb-046c-46a5-8344-e23e2ace71c0_                              _LP Consulting Engineers Inc.            _9911323             

I tried them with your solution and was able to reproduce the issue.
Attaching updated solution as well…
TestVersion.zip (7.5 KB)

I also tired previous online website generator with trailing spaces included and still have both Version 7 (45x45) generated as I would like it to be through the Aspose library.

Yes, this code demonstrates the problem. The task is in active state.