我使用第三方dll集成zteco生物识别设备。我通过使用TlbImp.exe并复制它来添加zkemkeeper.dll。
这是我的主要代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace RTEvents
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}
private void connectionToolStripMenuItem_Click(object sender, EventArgs e)
{
Connectivity con = new Connectivity();
con.MdiParent = this;
con.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
con.ControlBox = false;
con.MaximizeBox = false;
con.MinimizeBox = false;
con.Text = "";
con.Dock = DockStyle.Fill;
con.Show();
}
private void Main_Load(object sender, EventArgs e)
{
try
{
IsMdiContainer = true;
WindowState = FormWindowState.Normal;
this.toolStripStatusLabel1.Text = "Checking device status...";
new Thread(() =>
{
Thread.CurrentThread.IsBackground = true;
Connection con = new Connection();
RealTimeEvents rt = new RealTimeEvents();
if (con.CheckConnectivity(Connection.axCZKEM1))
{
this.toolStripStatusLabel1.Text = "Device connected";
con.DeviceProcess(rt);
}
else
{
this.toolStripStatusLabel1.Text = "Device not connected";
}
}).Start();
}
catch { }
}
public void setStatusLabel(string text)
{
this.toolStripStatusLabel1.Text = text;
}
}
}
我的连接类
using System;
使用System.Collections.Generic; 使用System.Text;
命名空间RTEvents { 类连接 { public static string IP =" 192.168.1.3&#34 ;; public static string PORT =" 4370&#34 ;; 公共静态字符串MACHINE_NUMBER =" 1&#34 ;; 公共静态字符串MASK =" 65535&#34 ;; public static zkemkeeper.CZKEMClass axCZKEM1 = new zkemkeeper.CZKEMClass(); public static bool isConnected = false; public void DeviceProcess(RealTimeEvents rt) {
if (Connection.axCZKEM1.RegEvent(Convert.ToInt32(MACHINE_NUMBER), Convert.ToInt32(MASK)))//Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all)
{
Connection.axCZKEM1.OnFinger += new zkemkeeper._IZKEMEvents_OnFingerEventHandler(rt.axCZKEM1_OnFinger);
Connection.axCZKEM1.OnVerify += new zkemkeeper._IZKEMEvents_OnVerifyEventHandler(rt.axCZKEM1_OnVerify);
Connection.axCZKEM1.OnAttTransactionEx += new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(rt.axCZKEM1_OnAttTransactionEx);
Connection.axCZKEM1.OnFingerFeature += new zkemkeeper._IZKEMEvents_OnFingerFeatureEventHandler(rt.axCZKEM1_OnFingerFeature);
Connection.axCZKEM1.OnEnrollFingerEx += new zkemkeeper._IZKEMEvents_OnEnrollFingerExEventHandler(rt.axCZKEM1_OnEnrollFingerEx);
Connection.axCZKEM1.OnDeleteTemplate += new zkemkeeper._IZKEMEvents_OnDeleteTemplateEventHandler(rt.axCZKEM1_OnDeleteTemplate);
Connection.axCZKEM1.OnNewUser += new zkemkeeper._IZKEMEvents_OnNewUserEventHandler(rt.axCZKEM1_OnNewUser);
Connection.axCZKEM1.OnHIDNum += new zkemkeeper._IZKEMEvents_OnHIDNumEventHandler(rt.axCZKEM1_OnHIDNum);
Connection.axCZKEM1.OnAlarm += new zkemkeeper._IZKEMEvents_OnAlarmEventHandler(rt.axCZKEM1_OnAlarm);
Connection.axCZKEM1.OnDoor += new zkemkeeper._IZKEMEvents_OnDoorEventHandler(rt.axCZKEM1_OnDoor);
Connection.axCZKEM1.OnWriteCard += new zkemkeeper._IZKEMEvents_OnWriteCardEventHandler(rt.axCZKEM1_OnWriteCard);
Connection.axCZKEM1.OnEmptyCard += new zkemkeeper._IZKEMEvents_OnEmptyCardEventHandler(rt.axCZKEM1_OnEmptyCard);
Connection.isConnected = true;
}
}
public void UnProcessDevice(RealTimeEvents rt)
{
Connection.axCZKEM1.Disconnect();
Connection.axCZKEM1.OnFinger -= new zkemkeeper._IZKEMEvents_OnFingerEventHandler(rt.axCZKEM1_OnFinger);
Connection.axCZKEM1.OnVerify -= new zkemkeeper._IZKEMEvents_OnVerifyEventHandler(rt.axCZKEM1_OnVerify);
Connection.axCZKEM1.OnAttTransactionEx -= new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(rt.axCZKEM1_OnAttTransactionEx);
Connection.axCZKEM1.OnFingerFeature -= new zkemkeeper._IZKEMEvents_OnFingerFeatureEventHandler(rt.axCZKEM1_OnFingerFeature);
Connection.axCZKEM1.OnEnrollFingerEx -= new zkemkeeper._IZKEMEvents_OnEnrollFingerExEventHandler(rt.axCZKEM1_OnEnrollFingerEx);
Connection.axCZKEM1.OnDeleteTemplate -= new zkemkeeper._IZKEMEvents_OnDeleteTemplateEventHandler(rt.axCZKEM1_OnDeleteTemplate);
Connection.axCZKEM1.OnNewUser -= new zkemkeeper._IZKEMEvents_OnNewUserEventHandler(rt.axCZKEM1_OnNewUser);
Connection.axCZKEM1.OnHIDNum -= new zkemkeeper._IZKEMEvents_OnHIDNumEventHandler(rt.axCZKEM1_OnHIDNum);
Connection.axCZKEM1.OnAlarm -= new zkemkeeper._IZKEMEvents_OnAlarmEventHandler(rt.axCZKEM1_OnAlarm);
Connection.axCZKEM1.OnDoor -= new zkemkeeper._IZKEMEvents_OnDoorEventHandler(rt.axCZKEM1_OnDoor);
Connection.axCZKEM1.OnWriteCard -= new zkemkeeper._IZKEMEvents_OnWriteCardEventHandler(rt.axCZKEM1_OnWriteCard);
Connection.axCZKEM1.OnEmptyCard -= new zkemkeeper._IZKEMEvents_OnEmptyCardEventHandler(rt.axCZKEM1_OnEmptyCard);
Connection.isConnected = false;
}
public bool CheckConnectivity(zkemkeeper.CZKEMClass axCZKEM1)
{
if (isConnected == false)
{
if (axCZKEM1.Connect_Net(IP, Convert.ToInt32(PORT)))
{
isConnected = true;
return isConnected;
}
else
{
return false;
}
}
return false;
}
}
}
这是错误,我不知道如何解决它 Thats the error
答案 0 :(得分:0)
构造类时抛出此类异常,无法分配特定的静态属性。
请参阅MDSN中的文档;
https://msdn.microsoft.com/en-us/library/system.typeinitializationexception(v=vs.110).aspx#Static
在你的班上,你有;
public static zkemkeeper.CZKEMClass ... = new zkemkeeper.CZKEMClass();
尝试删除它(用于调试目的)并查看是否仍然抛出异常。如果不是,那么你知道这就是问题所在。至于潜在的问题,我们需要更多关于这个zkemkeeper dll的信息。