Home > Enterprise >  Type or namespace 'zkemkeeper' cannot be found even after referencing the zkemkeeper.dll f
Type or namespace 'zkemkeeper' cannot be found even after referencing the zkemkeeper.dll f

Time:01-03

I have a C# program that I can run just fine within Visual Studio but it doesn't work when I try compiling it using a console like Command Prompt (csc Program.cs) even after referencing the zkemkeeper.dll file and added the using directive as well (error shown in screenshot). zkemkeeper error message when attempting to compile C# code

I have found 3 solutions but none of them worked for me:

  1. Changing the C# version:

I couldn't do that since I'm targeting a specific .NET framework (v4.8.1).Couldn't change C# version

  1. Downloading and installing the ZKemkeeper NuGet package:

Didn't work.

  1. Changing the LangVersion to 'latest' in the .csproj file:

Didn't work.

Any help would be much appreciated.


using System;
using zkemkeeper;

namespace ZKTEco_Biometric_Device_Integration
{
    internal class Program
    {
        public Program()
        {
        }

        public enum CONSTANTS
        {
            PORT = 4370,
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Connecting...");
            CZKEM objCZKEM = new CZKEM();
            if (objCZKEM.Connect_Net("192.168.1.11", (int)CONSTANTS.PORT))
            {
                Console.WriteLine("Connection Successful!");
            }
            else
            {
                Console.WriteLine("Connection Failed!");
            }
            Console.WriteLine("Obtaining attendance data...");
            if (objCZKEM.ReadGeneralLogData(objCZKEM.MachineNumber))
            {
                string dwEnrollNumber;
                int dwVerifyMode;
                int dwInOutMode;
                int dwYear;
                int dwMonth;
                int dwDay;
                int dwHour;
                int dwMinute;
                int dwSecond;
                int dwWorkCode = 1;
                int AWorkCode;
                objCZKEM.GetWorkCode(dwWorkCode, out AWorkCode);
                //objCZKEM.SaveTheDataToFile(objCZKEM.MachineNumber, "attendance.txt", 1);
                while (true)
                {
                    if (!objCZKEM.SSR_GetGeneralLogData(
                    objCZKEM.MachineNumber,
                    out dwEnrollNumber,
                    out dwVerifyMode,
                    out dwInOutMode,
                    out dwYear,
                    out dwMonth,
                    out dwDay,
                    out dwHour,
                    out dwMinute,
                    out dwSecond,
                    ref AWorkCode
                    ))
                    {
                        break;
                    }
                    Console.WriteLine("User ID:"   dwEnrollNumber   " "   verificationMode(dwVerifyMode)   " "   InorOut(dwInOutMode)   " "   dwDay   "/"   dwMonth   "/"   dwYear   " "   time(dwHour)   ":"   time(dwMinute)   ":"   time(dwSecond));
                }
                Console.ReadLine();
            }
        }

        static string time(int Time)
        {
            string stringTime = "";
            if (Time < 10)
            {
                stringTime = "0"   Time.ToString();
            }
            else
            {
                stringTime = Time.ToString();
            }
            return stringTime;
        }

        static string verificationMode(int verifyMode)
        {
            String mode = "";
            switch (verifyMode)
            {
                case 0:
                    mode = "Password";
                    break;
                case 1:
                    mode = "Fingerprint";
                    break;
                case 2:
                    mode = "Card";
                    break;
            }
            return mode;
        }

        static string InorOut(int InOut)
        {
            String InOrOut = "";
            switch (InOut)
            {
                case 0:
                    InOrOut = "IN";
                    break;
                case 1:
                    InOrOut = "OUT";
                    break;
                case 2:
                    InOrOut = "BREAK-OUT";
                    break;
                case 3:
                    InOrOut = "BREAK-IN";
                    break;
                case 4:
                    InOrOut = "OVERTIME-IN";
                    break;
                case 5:
                    InOrOut = "OVERTIME-OUT";
                    break;

            }
            return InOrOut;
        }
    }
}

CodePudding user response:

I've solved the problem by doing the following steps:

  1. Changing the project type from Console App (.NET Framework) to Console App by creating a new project and moving over all progress made.

  2. Publishing the project from Visual Studio to an external folder (Build -> Publish Selection -> Publish). Make sure to choose 'Framework-dependent' as the deployment mode.

  3. Navigating to the same directory that contains the executable file within Command Prompt.

  4. Executing the file from Command Prompt just like any other executable file.

  • Related