codebude / QRCoder

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

Cannot implicitly convert type `QRCoder.QRCodeData' to `QRCoder.QRCodeData' #48

Closed vishalpvr123456 closed 7 years ago

vishalpvr123456 commented 7 years ago

i got this error in unity "Cannot implicitly convert type QRCoder.QRCodeData' toQRCoder.QRCodeData'" help me out guys...thnks in advanced

codebude commented 7 years ago

Could you please give a little more sample code. Just from reading this short error text, it is hard to analyze what is going wrong.

vishalpvr123456 commented 7 years ago

screen shot 2016-09-06 at 10 10 32 am screen shot 2016-09-06 at 10 11 29 am

vishalpvr123456 commented 7 years ago

Above i put my project screenshot i hope it will be help to understand my problem or error. I am trying your code in unity 5.3.1f so its a problem or other .... please help me ...thanks

codebude commented 7 years ago

This problem looks strange, because both types seem to be the same, so no cast should be needed. Nevertheless, have you tried to cast?

You could test the following three variants. (Please tell me if one of it worked for you.)

1) QRCodeData qrCodeData = (QRCodeData)qrGenerator.CreateQrCode("Hi", QRCodeGenerator.ECCLevel.Q);

2) QRCodeData qrCodeData = (qrGenerator.CreateQrCode("Hi", QRCodeGenerator.ECCLevel.Q) as QRCodeData);

3) var qrCodeData = qrGenerator.CreateQrCode("Hi", QRCodeGenerator.ECCLevel.Q);

vishalpvr123456 commented 7 years ago

None of these are not working..still i got same error

codebude commented 7 years ago

Can copy the stacktrace or send a more detailed log of the error? Otherwise, would you mind to upload your sample unity project, so that I can test it on my hardware?

vishalpvr123456 commented 7 years ago

QR Generator.unitypackage.zip

vishalpvr123456 commented 7 years ago

i sent you unity package of my project in zip..

vishalpvr123456 commented 7 years ago

Hello, You tested my project ?

codebude commented 7 years ago

I think I got the problem. You "imported" QRCoder libs twice. On the one hand you imported the QRCoder.dll as reference and on the other hand, you added QRCodeData.cs and UnityQRCoder.cs as single files.

When Mono/Unity tries to compile, it prefers the .cs-files over the .dll. Unfortunately your .cs-files are in a different version and you added just some .cs-files but not all, which are needed. So it comes to an conflict between the .cs-file QRCoder implementation and the .dll QRCoder lib.

The easiest way to fix this, is to remove the both .cs-files (QRCodeData.cs, UnityQRCode.cs) from your Mono project. Then the complete code will be delivered by the QRCoder.dll.

vishalpvr123456 commented 7 years ago

If i remove both than it will work ? because all QR Code generator code in those files so i ask you

codebude commented 7 years ago

Yes that's correct. You just need the QRCoder.dll (and of course your own coding in the Behaviour.cs file). Please give a quick feedback, if it worked for you.

vishalpvr123456 commented 7 years ago

not even require of UnityQRCode.cs ? i am confuse here ...please

codebude commented 7 years ago

In the unitypackage you uploaded some posts ago, there were multiple files. Besides others I found the "QRCoder.dll", "UnityQRCode.cs" and "QRCodeData.cs".

You only need the QRCoder.dll - the DLL file is the complete library packed into one file. It holds the compiled versions of UnityQRCode.cs, QRCodeData.cs and all the other .cs-files of the QRCoder library.

So you have the choice. Either you include all source files from this Github repository (except the QRCoder.dll), then the library will be compiled, when your Unity project will be compiled.

Or you just embed the QRCoder.dll in you Unity project and forget about all .cs-files. The first option gives you the chance to rewrite or change the QRCoder library. The second option, is easier to implement and has less overhead.

At the moment you took a bit of both approaches. You included the QRCoder.dll and some of the .cs-files. Since the QRCoder.dll has another version as the .cs-files you embedded, Unity/MonoDevelop finds a conflict. He tries to map the QRCodeData object from the cs-file to the version of QRCodeData from the DLL library. Since they're are not at the same version you get the error.

By removing the .cs-files Unity/Monodevelop will take all code from the .dll-file. So your solution should become consistent and so the error should be resolved.

codebude commented 7 years ago

@vishalpvr123456 Did my solution work for you?

vishalpvr123456 commented 7 years ago

ArgumentException: The Assembly System.Drawing is referenced by QRCoder ('Assets/Plugins/QRCoder.dll'). But the dll is not allowed to be included or could not be found. UnityEditor.AssemblyHelper.AddReferencedAssembliesRecurse (System.String assemblyPath, System.Collections.Generic.List1 alreadyFoundAssemblies, System.String[] allAssemblyPaths, System.String[] foldersToSearch, System.Collections.Generic.Dictionary2 cache, BuildTarget target) (at /Users/builduser/buildslave/unity/build/Editor/Mono/AssemblyHelper.cs:156) UnityEditor.AssemblyHelper.AddReferencedAssembliesRecurse (System.String assemblyPath, System.Collections.Generic.List1 alreadyFoundAssemblies, System.String[] allAssemblyPaths, System.String[] foldersToSearch, System.Collections.Generic.Dictionary2 cache, BuildTarget target) (at /Users/builduser/buildslave/unity/build/Editor/Mono/AssemblyHelper.cs:162) UnityEditor.AssemblyHelper.FindAssembliesReferencedBy (System.String[] paths, System.String[] foldersToSearch, BuildTarget target) (at /Users/builduser/buildslave/unity/build/Editor/Mono/AssemblyHelper.cs:194) UnityEditor.HostView:OnGUI()

vishalpvr123456 commented 7 years ago

i got this error after removing files and this error comes at build time

codebude commented 7 years ago

Seems like something with your compilation target isn't right. You could try this answer: http://answers.unity3d.com/questions/53170/using-drawing-package-like-systemdrawing.html

Or otherwise you could use the PCL version of QRCoder (which I released last Saturday). Indeed the PCL version only has the BitmapByteQRCode class and not the UnityQRCode class, but therefore it's crossplatform. And there are also methods to create a Texture2D from the byte[] which is generated by the QRCoder PCL.