QRCoder icon indicating copy to clipboard operation
QRCoder copied to clipboard

.NET 6.0 - TypeLoadException

Open danielgindi opened this issue 2 years ago • 26 comments

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 -->

danielgindi avatar Mar 22 '22 10:03 danielgindi

Same here.

Anduin2017 avatar Mar 27 '22 06:03 Anduin2017

Same here

TruffleMuffin avatar Apr 02 '22 12:04 TruffleMuffin

Same here

onatsko avatar Apr 18 '22 20:04 onatsko

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

onatsko avatar Apr 18 '22 20:04 onatsko

same here

pauledrupt avatar Apr 25 '22 20:04 pauledrupt

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!

Darkfeast avatar May 12 '22 09:05 Darkfeast

Error : cs0246 : namespace 'QRCode' not found

hakimben13000 avatar May 13 '22 09:05 hakimben13000

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?

d-barker avatar May 17 '22 16:05 d-barker

Same here while upgrading to net6...

aguarino77 avatar Jul 18 '22 09:07 aguarino77

Same here while upgrading to net6...

adbdehghan avatar Jul 19 '22 12:07 adbdehghan

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

Anduin2017 avatar Aug 04 '22 06:08 Anduin2017

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 😔.

abhith avatar Aug 04 '22 06:08 abhith

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.

danielgindi avatar Aug 04 '22 07:08 danielgindi

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.

willshoemaker avatar Oct 06 '22 21:10 willshoemaker

@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

rdhainaut avatar Nov 28 '22 17:11 rdhainaut

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.

thomasgalliker avatar Dec 02 '22 10:12 thomasgalliker

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

MC-Swanepoel avatar Jan 10 '23 12:01 MC-Swanepoel

Is this library still maintained?

thomasgalliker avatar Jan 10 '23 16:01 thomasgalliker

Last update was December 2022

On Tue, 10 Jan 2023 at 6:17 PM, Thomas Galliker @.***> wrote:

Is this library still maintained?

— Reply to this email directly, view it on GitHub https://github.com/codebude/QRCoder/issues/393#issuecomment-1377512431, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWAUQIEBCP6NDXAPMC7XA33WRWDQHANCNFSM5RKL47HQ . You are receiving this because you commented.Message ID: @.***>

MC-Swanepoel avatar Jan 10 '23 16:01 MC-Swanepoel

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.

thomasgalliker avatar Jan 10 '23 16:01 thomasgalliker

Yes it does net, but if you roll back your version to 1.1 it works

On Tue, 10 Jan 2023 at 6:58 PM, Thomas Galliker @.***> wrote:

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.

— Reply to this email directly, view it on GitHub https://github.com/codebude/QRCoder/issues/393#issuecomment-1377568502, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWAUQIBZVYSHGFFDA5XVPM3WRWIJ3ANCNFSM5RKL47HQ . You are receiving this because you commented.Message ID: @.***>

MC-Swanepoel avatar Jan 10 '23 17:01 MC-Swanepoel

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?

thomasgalliker avatar Jan 10 '23 17:01 thomasgalliker

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

tldr: DotNet 6 changed something and the library followed:

https://github.com/codebude/QRCoder/issues/361#issuecomment-992152570

ThaDaVos avatar Feb 17 '23 07:02 ThaDaVos

Thanks, I'll check it out.

On Fri, 17 Feb 2023 at 9:53 AM, ThaDaVos @.***> wrote:

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

tldr: DotNet 6 changed something and the library followed:

#361 (comment) https://github.com/codebude/QRCoder/issues/361#issuecomment-992152570

— Reply to this email directly, view it on GitHub https://github.com/codebude/QRCoder/issues/393#issuecomment-1434258896, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWAUQIES6BL36FAZUOPLWC3WX4VA3ANCNFSM5RKL47HQ . You are receiving this because you commented.Message ID: @.***>

MC-Swanepoel avatar Feb 17 '23 08:02 MC-Swanepoel

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

thanks a lot, it worked.

salihacr avatar Apr 17 '23 14:04 salihacr

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

  • #495

Shane32 avatar Apr 13 '24 19:04 Shane32