0

I started off from the thread to [decode data matrix in C#] (How To Use ZXing C# Port)! but I am encountering an error that prevents me from using zxing.

error states: "The type or namespace name 'com' could not be found (are you missing a using directive or an assembly reference?)"

In my code i am (trying to) use:

using com.google.zxing;    

Please let me know what I am doing wrong.

Community
  • 1
  • 1
JayI
  • 1
  • Are you 100% sure you have referenced the ZXing library, either as a DLL or as a NuGet package? – Solal Pirelli Apr 20 '15 at 20:18
  • No. Perhaps thats the issue. Can you please share a reference so I can go ahead and reference ZXing correctly? Thanks. – JayI Apr 20 '15 at 20:32

2 Answers2

0

It'd be nice if C# could automatically detect the references you're using and download them, but this is not the case. You need to download the ZXing SDK and reference it before using it.

The easiest way to do so is via NuGet, which is built in Visual Studio from 2012 onwards, and available for VS 2010. Right-click on your project, click on "Manage NuGet Packages", then select "Online" from the left-hand menu and search with the search box in the top right.

There are two ZXing ports available on NuGet, so you'll have to look at them both and pick the one that seems right for you.

You can also find some ZXing DLL on the Internet and reference it from your project: right-click on your project's "References", click on "Add reference..." then on the "Browse" button.
However, that is not as convenient as NuGet because you need to manually check for updates to the library, and update the DLL, whereas NuGet will tell you when an update is available (it won't force you to update).

Just by looking at your code sample, I wouldn't suggest using a port that uses Java-like namespaces (a more C#-y version would be e.g. "Google.ZXing"), since it sounds like a "dumb" port that simply converted the Java syntax to C# without thinking about whether some C# features are better at doing whatever the original library wanted to do.
I've used ZXing.Net v0.14 in a Windows Phone app and it works well.

Solal Pirelli
  • 1,199
  • 9
  • 21
  • Thanks for the detailed answer. For now I got the ZXing DLL to start. I am using VS2010 and your instructions: " Right-click on your project, click on "Manage NuGet Packages", then select "Online" from the left-hand menu and search with the search box in the top right." didn't work for me. Perhaps its version dependent? – JayI Apr 22 '15 at 21:34
0

You have to replace using com.google.zxing; with using ZXing; if you are referencing and using the ZXing.Net assemblies. I replaced the Java-stylish namespaces with a more .Net like version. Old sample around the web doesn't work with ZXing.Net. In the source code repository and the download section of ZXing.Net you will find some more up-to-date samples. You should really start with the newer samples because I wrote some simplifications on top of the port.

Michael
  • 2,361
  • 1
  • 15
  • 15