Skip to content

.NET 6.0 - TypeLoadException #393

Closed
Closed

Description

@danielgindi

Type of issue

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

Expected Behavior

Should load the assembly.

Current Behavior

Referencing the library throws a TypeLoadException, with zero information.
This happens when targeting .NET 6.0, and the actual dll copied to the bin folder is that of the .NET 6.0 (~120KB).
When overwriting with the .NET Standard dll, or the .NET 5.0 dll - it works.

Possible Solution (optional)

Recompile?

Steps to Reproduce (for bugs)

  1. New project
  2. Target .NET 6.0
  3. Reference QRCoder 1.4.3
  4. Reference any class from the library

Your Environment

  • Version used: 1.4.3
  • Compiled from source or NuGet package?: NuGet
  • Payload/Encoded text:
  • Used payload generator:
  • Used ECC-level:
  • Used renderer class:
  • Environment (.NET 3.5, .NET 4.X, .NETCore, ...): .NET 6.0
    -->

Activity

  1. Anduin2017 commented on Mar 27, 2022

    @Anduin2017

    Same here.

  2. TruffleMuffin commented on Apr 2, 2022

    @TruffleMuffin

    Same here

  3. onatsko commented on Apr 18, 2022

    @onatsko

    Same here

  4. onatsko commented on Apr 18, 2022

    @onatsko

    all works fine with version Include="QRCoder" Version="1.4.1"

  5. pauledrupt commented on Apr 25, 2022

    @pauledrupt

    same here

  6. Darkfeast commented on May 12, 2022

    @Darkfeast

    all works fine with version Include="QRCoder" Version="1.4.1"

    thanks , I can't find class QRCode in 1.4.3 , 1.4.1 is fine!

  7. hakimben13000 commented on May 13, 2022

    @hakimben13000

    Error : cs0246 : namespace 'QRCode' not found

  8. d-barker commented on May 17, 2022

    @d-barker

    I have the same or similar issue,

    I am on a cross platform build, local macos and remote alpine linux container. We are in the process of upgrading from 3.1 to net6.0. And we came across this issue.

    My error is as follows:

    System.TypeLoadException : Could not load type 'ImageType' from assembly 'QRCoder, Version=1.4.3.0, Culture=neutral, PublicKeyToken=c4ed5b9ae8358a28'.
    

    Rolling back to 1.4.1 does not help my case, as I get a new exception throwing,

    Failed to create QR Code due to error: The type initializer for 'Gdip' threw an exception. System.TypeInitializationException: The type initializer for 'Gdip' threw an exception.
     ---> System.PlatformNotSupportedException: System.Drawing.Common is not supported on non-Windows platforms. See https://aka.ms/systemdrawingnonwindows for more information.
    

    dotnet 6.0 removes support for the System.Drawing.Common only supported on Windows:
    https://docs.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/6.0/system-drawing-common-windows-only

    Looks like the base64 encoder will need to find a cross platform alternative, PR anyone?

  9. aguarino77 commented on Jul 18, 2022

    @aguarino77

    Same here while upgrading to net6...

  10. adbdehghan commented on Jul 19, 2022

    @adbdehghan

    Same here while upgrading to net6...

  11. Anduin2017 commented on Aug 4, 2022

    @Anduin2017

    Is this project still being maintained? Now the basic demo in the home readme can produce this issue. Please fix this.

  12. abhith commented on Aug 4, 2022

    @abhith

    Do we have any alternatives to this library that works in .net6?
    Because of this issue, our project migration from .net5 to .net6 is blocked and we are almost close to .net7, so can't wait more 😔.

  13. danielgindi commented on Aug 4, 2022

    @danielgindi
    Author

    You can enable System.Drawing for .NET 6. It's disabled by default because some features are not available cross-platform, but this library does not use any of those.

  14. willshoemaker commented on Oct 6, 2022

    @willshoemaker

    There are conditional compilation symbols in the QRCode class
    #if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS
    The NET6_0_WINDOWS part is the problem. It is causing that class to not be compiled into the normal net6.0 package, which is the one that visual studio pulls in when compiling if your target framework is net6.0

    If you explicitly load the library from the netstandard2.0 folder instead the library works. You can technically even just replace the .dll in the output directory with the one from the netstandard2.0 folder. I would guess setting your target framework to net6.0-windows would also work.

    I don't know if this is because of a compatibility issue with some dependency or just an oversight. But it's essentially making the net6.0 version of the library match the netstandard1.3 version of the library - which doesn't have the QRCode class.

    I'd guess the compilation symbol should be NET5_0_OR_GREATER, but again I don't know if this was intentional or not.

  15. rdhainaut commented on Nov 28, 2022

    @rdhainaut

    @willshoemaker thanks for your comment

    You can set option of your project to run on 'Windows' target
    Right clic on your project -> properties -> Application/General/TargetOs [Windows]
    image

  16. thomasgalliker commented on Dec 2, 2022

    @thomasgalliker

    I'm using QRCoder in a platform-independant (netstandard2.0) library which is then used in a .net6.0 project. It defeats the purpose to set TFM to net6.0-windows if I want to target both, windows and linux.

    Rolling back to QRCoder 1.4.1 until this issue is resolved.

  17. MC-Swanepoel commented on Jan 10, 2023

    @MC-Swanepoel

    My issue was also not detecting the QRCode class, So rolling back to version 1.4.1 worked for me.

    If you have another issue I am not sure if rolling the version back will work

  18. thomasgalliker commented on Jan 10, 2023

    @thomasgalliker

    Is this library still maintained?

  19. MC-Swanepoel commented on Jan 10, 2023

    @MC-Swanepoel
  20. thomasgalliker commented on Jan 10, 2023

    @thomasgalliker

    Okay. Because it looks like the latest version of this library doesn't work with .NET 6 - and .NET 6 is also pretty old already.

  21. MC-Swanepoel commented on Jan 10, 2023

    @MC-Swanepoel
  22. thomasgalliker commented on Jan 10, 2023

    @thomasgalliker

    That's what I did - and yes it works with an older version, thanks. But this is not a permanent solution, rather a quick workaround, do you agree?

  23. ThaDaVos commented on Feb 17, 2023

    @ThaDaVos

    In the following issue may be the explanation to why it has changed

    tldr: DotNet 6 changed something and the library followed:

    #361 (comment)

  24. MC-Swanepoel commented on Feb 17, 2023

    @MC-Swanepoel
  25. salihacr commented on Apr 17, 2023

    @salihacr

    all works fine with version Include="QRCoder" Version="1.4.1"

    thanks a lot, it worked.

  26. Shane32 commented on Apr 13, 2024

    @Shane32
    Owner

    Looks like the base64 encoder will need to find a cross platform alternative, PR anyone?

  27. Shane32 commented on Oct 2, 2025

    @Shane32
    Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions