codebude / QRCoder

A pure C# Open Source QR Code implementation
MIT License
4.46k stars 1.09k forks source link

Not working OOT on Debian 10 #284

Closed Georg1337 closed 3 years ago

Georg1337 commented 3 years ago

Type of issue

[x] Bug
[ ] Question (e.g. about handling/usage)
[ ] Request for new feature/improvement

Expected Behavior

reference project as "QRCoder" (= pull from nuget.org) and be able to use it in my code

Current Behavior

Windows: works Linux: Could not load type 'QRCoder.QRCode' from assembly 'QRCoder, Version=1.4.2.0, Culture=neutral, PublicKeyToken=null'

Possible Solution (optional)

Test this library on Debian 10 (haven't tried on other distros, maybe they fail too). Make it compilable OOT

Steps to Reproduce (for bugs)

  1. dotnet add package QRCoder 1.4.1
  2. use class QRCoder.QRCode somewhere in code
  3. dotnet build

Your Environment

OS: Debian 10
#/etc/os-release
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
error

Could not load type 'QRCoder.QRCode' from assembly 'QRCoder, Version=1.4.2.0, Culture=neutral, PublicKeyToken=null'

package reference

<PackageReference Include="QRCoder" Version="1.4.1" />

code, that generates error
// CODE
public List<Bitmap> generate(List<string> GUIDs, int pixelSize = 15)
{
    List<Bitmap> qrCodes = new List<Bitmap>();
    foreach (var GUID in GUIDs) {
        QRCodeData qrCodeData = m_qrGenerator.CreateQrCode(GUID, QRCoder.QRCodeGenerator.ECCLevel.H);
        QRCode qrCode = new QRCode(qrCodeData);
        Bitmap qrCodeImage = qrCode.GetGraphic(pixelSize);

        qrCodes.Add(qrCodeImage);
    }

    return qrCodes;
}
// CODE
dotnet version
$ dotnet --version
5.0.202

Note

this does work OOT on windows! After numerous attempts I tried to compile the lib myself. It works OOT on windows 10. Just clone this repo, go to the directory and run dotnet build.

On linux on the otherhand I get:

[...]
/usr/share/dotnet/sdk/5.0.202/Microsoft.Common.CurrentVersion.targets(1216,5): error MSB3644: The reference assemblies for .NETFramework,Version=v3.5 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks [/root/temp/qrcoder_custom/QRCoder/QRCoder.csproj]
/usr/share/dotnet/sdk/5.0.202/Microsoft.Common.CurrentVersion.targets(1216,5): error MSB3644: The reference assemblies for .NETFramework,Version=v3.5 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks [/root/temp/qrcoder_custom/QRCoderTests/QRCoderTests.csproj]
    82 Warning(s)
    2 Error(s)

Since I just need QRCoder, I then switched to the QRCoder directory. After changing <TargetFrameworks>net35;net40;netstandard1.1;netstandard2.0</TargetFrameworks> to <TargetFramework>net5.0</TargetFramework> it compiles. I tried to reference this sub-directory project ($repo-root/QRCoder/QRCoder.csproj) in my project, but get a similar error, but without the mention of an Assembly (probably because I'm referencing another project):

/root/temp/imr.qrcodegenerator/QRCodeGenerator.cs(21,17): error CS0246: The type or namespace name 'QRCode' could not be found (are you missing a using directive or an assembly reference?) [/root/temp/imr.qrcodegenerator/IMR.QRCodeGenerator.csproj]
/root/temp/imr.qrcodegenerator/QRCodeGenerator.cs(21,37): error CS0246: The type or namespace name 'QRCode' could not be found (are you missing a using directive or an assembly reference?) [/root/temp/imr.qrcodegenerator/IMR.QRCodeGenerator.csproj]
/root/temp/imr.qrcodegenerator/QRCodeGenerator.cs(32,13): error CS0246: The type or namespace name 'QRCode' could not be found (are you missing a using directive or an assembly reference?) [/root/temp/imr.qrcodegenerator/IMR.QRCodeGenerator.csproj]
/root/temp/imr.qrcodegenerator/QRCodeGenerator.cs(32,33): error CS0246: The type or namespace name 'QRCode' could not be found (are you missing a using directive or an assembly reference?) [/root/temp/imr.qrcodegenerator/IMR.QRCodeGenerator.csproj]
    0 Warning(s)
    4 Error(s)

I haven't tried any further, since I think this is strange and I wanted to post this as an issue. To me it seems like QRCoder is just not linux compatible out of the box and needs some adjustments. I will try further to make it compatible with my project. Maybe someone knows what my issue could be. I'm relatively new to .NET cross compiling (developing my app on windows, shipping to linux). Maybe I'm just missing something crucial.

Thanks in advance

Georg1337 commented 3 years ago

Not sure if this is allowed, but for anyone having similar issues, it probably helps to try out this QR-Code lib: https://github.com/manuelbl/QrCodeGenerator

Altough most of the search results for C# QR-Code libs direct to this repository, the one I linked worked well for me. Even tough it took some time to pop out in my searches.

codebude commented 3 years ago

Hi @Georg1337 ,

for me it's working totally fine on Ubuntu Linux with .NET 5.0.202. 2021-04-26 16_01_38-raffael@DESKTOP-6E543V4_ _mnt_c_Users_Raffael Herrmann_Drive_Sourcecode_C# Proje

Two ideas:

Georg1337 commented 3 years ago

Hi @Georg1337 ,

for me it's working totally fine on Ubuntu Linux with .NET 5.0.202. 2021-04-26 16_01_38-raffael@DESKTOP-6E543V4_ _mnt_c_Users_Raffael Herrmann_Drive_Sourcecode_C# Proje

Two ideas:

* Have you installed the package via `dotnet add package QRCoder`

* Have you added the using-statement (`using QRCoder;`) at the beginning of your code file? (Without the using statement you will also get MSB3644-errors...)

yes, I did it exactly that way. And as stated, my code does actually work on windows. Seems really strange, that it does not work only for me.

codebude commented 3 years ago

Wait a moment...

/root/temp/imr.qrcodegenerator/QRCodeGenerator.cs(21,17): error CS0246: ...

The error points to line 21. But line 21 in QRCodeGenerator class has no such reference: https://github.com/codebude/QRCoder/blob/master/QRCoder/QRCodeGenerator.cs#L21

Could it be that your program has also a class called "QRCodeGenerator"? If so, dotnet struggles to decide if QRCode should be taken from your project/class or from QRCoder.

Either try to rename your class or reference QRCoder via fullpath like:

// CODE
public List<Bitmap> generate(List<string> GUIDs, int pixelSize = 15)
{
    List<Bitmap> qrCodes = new List<Bitmap>();
    QRCoder.QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator();
    foreach (var GUID in GUIDs) {
        QRCoder.QRCodeData qrCodeData = qrGenerator.CreateQrCode(GUID, QRCoder.QRCodeGenerator.ECCLevel.H);
        QRCoder.QRCode qrCode = new QRCoder.QRCode(qrCodeData);
        Bitmap qrCodeImage = qrCode.GetGraphic(pixelSize);

        qrCodes.Add(qrCodeImage);
    }

    return qrCodes;
}
// CODE
codebude commented 3 years ago

Hi @Georg1337 ,

can you try out, if the solution above solves your problem? Or have you settled to another library? (If so, I would close this issue.)

codebude commented 3 years ago

Issue closed due to lack of feedback. If the problem still occurs, please re-open the ticket.