DirectoryServices Cast Error?

B

Bmack500

Hello, and Thanks in advance!
Using: Vstudio 2005, XP, .NET 2.0

I'm getting the following error when running my code below. I'm
passing an object array which contains other variables. It happens
immediately when it hits the "For" loop:

Unable to cast COM object of type 'System.__ComObject' to interface
type 'IDirectorySearch'. This operation failed because the
QueryInterface call on the COM component for the interface with IID
'{109BA8EC-92F0-11D0-A790-00C04FD8D5A8}' failed due to the following
error: No such interface supported (Exception from HRESULT: 0x80004002
(E_NOINTERFACE)).

I also have a problem where in my "New" method, it gives me a late
binding error with option strict on.

I'm basically creating multiple threads from this thread to go and do
some time consuming work, which doesn't require much processing power
or resources.

Option Strict Off
Imports System.Text.RegularExpressions
Public Class controlThreadClass
Dim svrInfo As serverInfo
Dim mtDict As Dictionary(Of Integer, String)
Dim svrResults As System.DirectoryServices.SearchResultCollection
Dim threadList As System.Collections.ArrayList
Dim objSrvr As System.DirectoryServices.SearchResult

Public Sub New(ByVal obj As Object)
svrInfo = DirectCast(obj(0), serverInfo)
mtDict = DirectCast(obj(1), Dictionary(Of Integer, String))
svrResults = DirectCast(obj(2),
System.DirectoryServices.SearchResultCollection)
End Sub

Public Sub ControlThread()
'This thread keeps the UI responsive and manages the
serverThread threads
Dim i2 As Integer = 1

Dim sThread As System.Threading.Thread
Dim creds As New secCreds
Dim su As New SwitchUser
Dim serverThread As serverThreadClass
Dim serverThreadVals As Object
Dim strVal As String

'Here's where my error occurs, as soon as you hit the "For" loop...
For Each objSrvr In svrResults

....other code here.....
End If
i2 += 1
Next

End Sub
End Class
 
B

Bmack500

Could you elaborate? Match in what way? Sorry, I'm diving head first
into multithreading; waiting for some books to arrive!
 
V

vbnetdev

Make sure the declaration of the object and the actions that occur with the
object exist in the same thread.
 
C

Cor Ligthert [MVP]

Bmack,
Any chance you could provide a quick example? Sorry, I hate to
impose....

We too, you are passing an object. First of all, try to avoid that secondly
we have not any idea what it can be, as far as I can see is it a Type that
holds all kinds of different Types.

That makes it in my idea almost impossible to answer your question.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top