codebude / QRCoder

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

Library uses System.Drawing so can't be used in ASP.NET projects #201

Closed peterlukerow closed 3 years ago

peterlukerow commented 5 years ago

Question

Microsoft's documentation says: https://docs.microsoft.com/en-us/dotnet/api/system.drawing?view=netframework-4.7.2 "Classes within the System.Drawing namespace are not supported for use within a Windows or ASP.NET service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions. For a supported alternative, see Windows Imaging Components."

I looked at the code for QrCode and see that it is using System.Drawning. Do you have any plans to release a version that can be used on an ASP.NET MVC project (full fat .NET framework)?

raboud commented 5 years ago

might be good to use ImageSharp instead of System.Drawing.

I used it for another similar project. If interested i could possibly implement it in a pull request

fakhrulhilal commented 5 years ago

Agree, having dependency to System.Drawing making it less usable for .net standard. I intend to use it in blazor it's not possible to do that due to this dependency to System.Drawing.

codebude commented 4 years ago

@peterlukerow Not all of the rendering classes use System.Drawing. If you want to avoid the usage of System.Drawing you could e.g. use one of the following renderer classes, which don't have references to System.Drawing:

peterlukerow commented 4 years ago

@codebude that's good to know.

Don't need to use it yet as there is still some project wrangling going on and this was just my reconnaissance. Hopefully if I do get to the point of using it the System.Drawing issue will have been resolved.

KurogamiLight3303 commented 4 years ago

I am using it in a ASP.net proyect with System.Drawing and it work ok

peterlukerow commented 4 years ago

I am using it in a ASP.net proyect with System.Drawing and it work ok

It's not that it won't work that is a problem it's that it can lead to memory leaks when used in ASP.NET - see my original opening question that quotes the Microsoft documentation.

codebude commented 3 years ago

Currently I'm not planning to move away from System.Drawing. For ASP.NET a bunch of rendering classes without usage of System.Drawing are available.

peterlukerow commented 3 years ago

Currently I'm not planning to move away from System.Drawing. For ASP.NET a bunch of rendering classes without usage of System.Drawing are available.

Having to explicitly check the source code kind of defeats the point of using a library which should be treated as a black box. Perhaps restructure the project into multiple DLLs so you have Core and Web. Thus anything in the Web DLL will not use System.Drawing for example, that way it's easy to only reference the parts that should be safe to use.

codebude commented 3 years ago

Hi @peterlukerow ,

I'll take your arguments into the discussion in https://github.com/codebude/QRCoder/issues/242 I guess the motivation of this issue is the same.