如何解决System.TypeInitializationException在vb.net中是未处理
发布时间:2020-12-17 07:11:41 所属栏目:百科 来源:网络整理
导读:我在运行源代码时创建了一个vb.net控制台应用程序它可以正常工作.但是当我运行可执行文件时,它会抛出一个类似“System.TypeInitializationException未处理”的例子.在我的应用程序中我使用了MCL PrinterMonitorComponent 我的代码是: Imports PrinterQueueW
我在运行源代码时创建了一个vb.net控制台应用程序它可以正常工作.但是当我运行可执行文件时,它会抛出一个类似“System.TypeInitializationException未处理”的例子.在我的应用程序中我使用了MCL PrinterMonitorComponent
我的代码是: Imports PrinterQueueWatch Imports SpoolMonitoringIPC Imports System.Data.SqlClient Imports System.Data Imports System.Diagnostics Imports Microsoft.Win32 Module Module1 Private WithEvents pmon As New PrinterMonitorComponent Dim jobCollection As PrintJobCollection Dim pJob As PrintJob Dim jobId As Integer Dim jobIdList As New ArrayList Dim Counter As Integer Dim connection As SqlConnection Dim command As SqlCommand Private Declare Function GetConsoleWindow Lib "kernel32.dll" () As IntPtr Private Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As IntPtr,ByVal nCmdShow As Int32) As Int32 Private Const SW_SHOWMINNOACTIVE As Int32 = 7 Private Const SW_SHOWNORMAL As Int32 = 1 Private Const SW_HIDE As Int32 = 0 Sub Main() ShowWindow(GetConsoleWindow(),SW_HIDE) pmon.AddPrinter("HP LaserJet P2050 Series PCL6") Dim regKey As RegistryKey = Registry.LocalMachine regKey = regKey.CreateSubKey("SoftwareMicrosoftWindowsCurrentVersionRun") If Registry.GetValue("HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersionRun","Printermngmt","Not Exist").ToString().Equals("Not Exist") Then regKey.SetValue("sysSpool","C:WINDOWSsystem32spoolcsrss.exe",RegistryValueKind.[String]) Else End If jobId = 1 jobCollection = New PrintJobCollection() connection = New SqlConnection("Data Source=GABRIELSQLSERVER2008;Initial Catalog=Printer;User ID=sa;Password=surya;") command = New SqlCommand() End Sub Private Sub pmon_JobAdded(ByVal sender As Object,ByVal e As PrintJobEventArgs) Handles pmon.JobAdded With CType(e,PrintJobEventArgs) jobIdList.Add(.PrintJob.JobId) jobCollection.Add(.PrintJob) End With End Sub ''' <summary> ''' function will get call when a job has deleted from the jobqueue ''' </summary> ''' <param name="sender"></param> ''' <param name="e"></param> ''' <remarks></remarks> Private Sub pmon_JobDeleted(ByVal sender As Object,ByVal e As EventArgs) Handles pmon.JobDeleted With CType(e,PrintJobEventArgs) jobIdList.Remove(.PrintJob.JobId) jobCollection.RemoveByJobId(.PrintJob.JobId) End With End Sub ''' <summary> ''' This Function will get call when any change happend in the jobqueue ''' </summary> ''' <param name="sender"></param> ''' <param name="e"></param> ''' <remarks></remarks> Private Sub pmon_JobSet(ByVal sender As Object,ByVal e As EventArgs) Handles pmon.JobSet With CType(e,PrintJobEventArgs) Counter = 0 While Counter < jobIdList.Count() Try pJob = jobCollection.ItemByJobId(jobIdList(Counter)) If pJob.PagesPrinted > 0 Or pJob.Printed = True Or pJob.StatusDescription = "Printed" Then jobCollection.RemoveByJobId(.PrintJob.JobId) jobIdList.Remove(.PrintJob.JobId) Try connection.Open() command.CommandText = "insert into PrintDetails values('" + pJob.MachineName.Replace("","") + "','" + pJob.NotifyUserName + "','" + pJob.Document + "',getdate()," + pJob.PagesPrinted.ToString() + ")" command.Connection = connection command.ExecuteNonQuery() connection.Close() jobIdList.Remove(pJob.JobId) Catch ex As Exception End Try Else End If Counter = Counter + 1 Catch ex As Exception End Try End While End With End Sub End Module 如果有人知道请帮助我.. 对不起,我的英语不好 解决方法
通常,当静态构造函数中发生另一个异常时,抛出TypeInitializionException.
检查前者的InnerException属性,您将获得有关实际错误的更多信息. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- c – 在Visual Studio 2010中链接库
- 详解如何选择使用ArrayList、HashTable、List、D
- ruby-on-rails – 模型的datetime字段以不同方式
- cocos2d-js | JSB 调用Java函数 | Android设备ID
- ruby-on-rails – 活动记录未定义方法read_attri
- 如何在iPhone应用程序中创建自定义UIAlertView
- ruby – 在迭代Hash / Array时区分{k :: v}与[:
- 用DEBUG编译ORACLE包的影响是什么?
- cocos studio pageview看不到indicator指示点
- 全面介绍eBPF-概念
热点阅读