我创建了一个自定义对象,但似乎无法将数组传递给它。我会在下面粘贴我的代码。我试图传递的数组是“UserProxies”。
我的对象:
Public Class obj
Public isPrimary As String
Public AccountName As String
Public DisplayName As String
Public mail As String
Public DistinguishName As String
Public HomeDirectory As String
Public EmployeeId As String
Public Description As String
Public HomeDrive As String
Public ScriptPath As String
Public telephoneNumber As String
Public mobile As String
Public streetAddress As String
Public City As String
Public Province As String
Public Country As String
Public postalCode As String
Public company As String
Public EmployeeTitle As String
Public profilePath As String
Public homeMDB As String
Public legacyExchangeDN As String
Public TargetAddress As String
Public Enabled As String
Public IsAccountLockedOut As String
Public BadLogonCount As String
Public LastBadPasswordAttempt As String
Public LastLogon As String
Public LastPasswordSet As String
Public ActiveSync As String
Public UserProxies() As String
Sub New(isprimary As String, AccountName As String, DisplayName As String, mail As String, DistinguishName As String, HomeDirectory As String, EmployeeId As String, Description As String, HomeDrive As String, ScriptPath As String, telephoneNumber As String, mobile As String, streetAddress As String, City As String, Province As String, Country As String, postalCode As String, company As String, EmployeeTitle As String, profilePath As String, homeMDB As String, legacyExchangeDN As String, TargetAddress As String, Enabled As String, IsAccountLockedOut As String, BadLogonCount As String, LastBadPasswordAttempt As String, LastLogon As String, LastPasswordSet As String, ActiveSync As String, UserProxies() As String)
Me.isPrimary = isprimary
Me.AccountName = AccountName
Me.DisplayName = DisplayName
Me.mail = mail
Me.DistinguishName = DistinguishName
Me.HomeDirectory = HomeDirectory
Me.EmployeeId = EmployeeId
Me.Description = Description
Me.HomeDrive = HomeDrive
Me.ScriptPath = ScriptPath
Me.telephoneNumber = telephoneNumber
Me.mobile = mobile
Me.streetAddress = streetAddress
Me.City = City
Me.Province = Province
Me.Country = Country
Me.postalCode = postalCode
Me.company = company
Me.EmployeeTitle = EmployeeTitle
Me.profilePath = profilePath
Me.homeMDB = homeMDB
Me.legacyExchangeDN = legacyExchangeDN
Me.TargetAddress = TargetAddress
Me.Enabled = Enabled
Me.IsAccountLockedOut = IsAccountLockedOut
Me.BadLogonCount = BadLogonCount
Me.LastBadPasswordAttempt = LastBadPasswordAttempt
Me.LastLogon = LastLogon
Me.LastPasswordSet = LastPasswordSet
Me.ActiveSync = ActiveSync
Me.UserProxies = UserProxies
End Sub
End Class
我填写的地方:
Public Shared UserProxies() As String 'The Public part is normal
If UserDirectory.Properties("proxyAddresses").Value IsNot Nothing Then
Dim ProxiesObj As Object = UserDirectory.Properties("proxyAddresses").Value 'Proxy to put into object first
Dim x As Integer = 0
For Each Item As String In ProxiesObj
ReDim Preserve UserProxies(x)
UserProxies(x) = Item
x = x + 1
Next
End If
UserObject.add(New obj(PrimaryAccount, AccountName, DisplayName, mail, DistinguishName, HomeDirectory, EmployeeId, Description, HomeDrive, ScriptPath, telephoneNumber, mobile, streetAddress, City, Province, Country, postalCode, company, EmployeeTitle, profilePath, homeMDB, legacyExchangeDN, TargetAddress, Enabled, IsAccountLockedOut, BadLogonCount, LastBadPasswordAttempt, LastLogon, LastPasswordSet, ActiveSync, UserProxies))
运行时收到错误消息:
An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
Additional information: Exception has been thrown by the target of an invocation.
其余的工作正常。只有在我将数组添加到其中时才会启动错误消息。
感谢您的帮助。
答案 0 :(得分:1)
由于我不允许对该问题发表评论。 (只有12个代表);-)
问题是当出现此异常时,尝试使用try catch块围绕此异常或进行进一步调试,可能问题不是将该数组作为数组本身的创建传递给对象。 / p>