title: An unhandled exception of type 'System.TypeInitializationException' occurred in RTEvents.exe
body: <p>I'm using third party dll to integrate zteco biometric device. I've add zkemkeeper.dll by using TlbImp.exe and making copy of it.</p>
  
  <p><a href="https://i.stack.imgur.com/dw7ga.png" rel="nofollow noreferrer">Here is my connection class</a></p>
  
  <p>Here is my main code</p>
  
  <pre><code>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(() =&gt;
                  {
                      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;
          }
  
  
      }
  }
  </code></pre>
  
  <p>my connection class</p>
  
  <pre><code>using System;
  </code></pre>
  
  <p>using System.Collections.Generic;
  using System.Text;</p>
  
  <p>namespace RTEvents
  {
      class Connection
      {
          public static string IP = "192.168.1.3";
          public static string PORT = "4370";
          public static string MACHINE_NUMBER = "1";
          public static string MASK = "65535";
          public static zkemkeeper.CZKEMClass axCZKEM1 = new zkemkeeper.CZKEMClass();
          public static bool isConnected = false;
          public void DeviceProcess(RealTimeEvents rt)
          {</p>
  
  <pre><code>        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;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>that's the error and I've no clue how to solve it
  <a href="https://i.stack.imgur.com/K2xsA.png" rel="nofollow noreferrer">Thats the error</a></p>