DebugPackage是一种类型,不能用作异常

时间:2012-01-28 12:23:52

标签: asp.net vb.net vb.net-2010

我有一个VB.net应用程序,我有一个带有此签名的函数:

Public Function DeSerializeAnObject(XmlOfAnObject As String, ObjectType As Type) As [Object]

但是跟随调用是错误的(在DebugPackage上):

 Dim obj As ObjectSerializer = New ObjectSerializer
        obj.DeSerializeAnObject("", TypeOf(DebugPackage))
  

DebugPackage是一种类型,不能用作异常。

1 个答案:

答案 0 :(得分:2)

您没有使用正确的关键字,您应该使用GetType代替TypeOf

Dim obj As New ObjectSerializer
obj.DeSerializeAnObject("", GetType(DebugPackage))

GetTypeTypeOf函数之间的差异:

Dim obj As String = ""

' TypeOf operator checks if an Object belongs to a Type. 
' It cannot be used without the "Is SomeType" part
Dim isString As Boolean = TypeOf obj is String

' GetType operator returns Type information for a specified Type
Dim type As Type = GetType(String)

' Also, objects have a GetType method to retrieve it's Type
type = obj.GetType()