本文整理汇总了VB.NET中System.TypeLoadException.TypeLoadException构造函数的典型用法代码示例。如果您正苦于以下问题:VB.NET TypeLoadException构造函数的具体用法?VB.NET TypeLoadException怎么用?VB.NET TypeLoadException使用的例子?那么恭喜您, 这里精选的构造函数代码示例或许可以为您提供帮助。
在下文中一共展示了TypeLoadException构造函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: Example
Public Class Example
Public Shared Sub Main()
Try
' Call a method that throws an exception.
TypeLoadExceptionDemoClass.GenerateException()
Catch e As TypeLoadException
Console.WriteLine("TypeLoadException:{0} {1}", vbCrLf, e.Message)
End Try
End Sub
End Class
Class TypeLoadExceptionDemoClass
Public Shared Function GenerateException() As Boolean
' Throw a TypeLoadException with a custom message.
Throw New TypeLoadException("This is a custom TypeLoadException error message.")
End Function
End Class
开发者ID:VB.NET开发者,项目名称:System,代码行数:17,代码来源:TypeLoadException 输出:
TypeLoadException:
This is a custom TypeLoadException error message.
示例2: GetObjectDataDemo
' 导入命名空间
Imports System.Reflection
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Soap
Imports System.Security.Permissions
Imports System.IO
Class GetObjectDataDemo
Public Shared Sub Main()
' Get a reference to the assembly mscorlib.dll, which is always
' loaded. (System.String is defined in mscorlib.)
Dim tString As Type = GetType(String)
Dim mscorlib As [Assembly] = tString.Assembly
Try
Console.WriteLine("Attempting to load a type not present in the assembly 'mscorlib'")
' This loading of invalid type raises a TypeLoadException
Dim myType As Type = mscorlib.GetType("System.NonExistentType", True)
Catch
' Serialize the exception to disk and reconstitute it.
Dim ErrorDatetime as System.DateTime = DateTime.Now
Console.WriteLine("A TypeLoadException has been raised.")
' Create MyTypeLoadException instance with current time.
Dim myException As new MyTypeLoadException(ErrorDatetime)
Dim myFormatter as IFormatter = new SoapFormatter()
Dim myFileStream as Stream
myFileStream = New FileStream("typeload.xml", FileMode.Create, FileAccess.Write, FileShare.None)
Console.WriteLine("Serializing the TypeLoadException with DateTime as " _
& ErrorDatetime.ToString())
' Serialize the MyTypeLoadException instance to a file.
myFormatter.Serialize(myFileStream, myException)
myFileStream.Close()
Console.WriteLine("Deserializing the Exception.")
myFileStream = New FileStream("typeload.xml", FileMode.Open, FileAccess.Read, FileShare.None)
' Deserialize and reconstitute the instance from file.
myException = CType(myFormatter.Deserialize(myFileStream), MyTypeLoadException)
myFileStream.Close()
Console.WriteLine("Deserialized exception has ErrorDateTime = " + myException.ErrorDateTime.ToString())
End Try
End Sub
End Class
' This class overrides the GetObjectData method and initializes
' its data with current time.
<Serializable()> _
Public Class MyTypeLoadException
Inherits TypeLoadException
Private _errorDateTime As System.DateTime = DateTime.Now
Public ReadOnly Property ErrorDateTime As DateTime
Get
Return _errorDateTime
End Get
End Property
Public Sub New(myDateTime As DateTime)
_errorDateTime = myDateTime
End Sub
Protected Sub New(sInfo As SerializationInfo, sContext As StreamingContext)
MyBase.New(sInfo, sContext)
' Reconstitute the deserialized information into the instance.
_errorDateTime = sInfo.GetDateTime("ErrorDate")
End Sub
' GetObjectData overrides must always have a demand for SerializationFormatter.
<SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter:=true)> _
Public Overrides Sub GetObjectData(sInfo As SerializationInfo, sContext As StreamingContext)
MyBase.GetObjectData(sInfo, sContext)
' Add a value to the Serialization information.
sInfo.AddValue("ErrorDate", ErrorDateTime)
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System,代码行数:79,代码来源:TypeLoadException
示例3: TypeLoadException_Constructor3
' 导入命名空间
Imports System.Runtime.InteropServices
Public Class TypeLoadException_Constructor3
Public Shared Sub Main()
Console.WriteLine("Calling a method in a non-existent DLL which triggers a TypeLoadException.")
Try
TypeLoadExceptionDemoClass.GenerateException()
Catch e As TypeLoadException
Console.WriteLine(("TypeLoadException: " + ControlChars.Cr + ControlChars.Tab + "Error Message = " + e.Message))
Console.WriteLine(("TypeLoadException: " + ControlChars.Cr + ControlChars.Tab + "InnerException Message = " + e.InnerException.Message))
Catch e As Exception
Console.WriteLine(("Exception: " + ControlChars.Cr + ControlChars.Tab + "Error Message = " + e.Message))
End Try
End Sub
End Class
Class TypeLoadExceptionDemoClass
' A call to this method will raise a TypeLoadException.
Public Declare Sub NonExistentMethod Lib "NonExistentDLL.DLL" Alias "MethodNotExists" ()
Public Shared Sub GenerateException()
Try
NonExistentMethod()
Catch e As TypeLoadException
' Rethrow exception with the exception as inner exception
Throw New TypeLoadException("This exception was raised due to a call to an invalid method.", e)
End Try
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System,代码行数:30,代码来源:TypeLoadException
注:本文中的System.TypeLoadException.TypeLoadException构造函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论