Home All Groups Group Topic Archive Search About

DirectoryServices Cast Error?

Author
21 Dec 2006 8:16 PM
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

Author
21 Dec 2006 9:48 PM
vbnetdev
Your calling thread and thread it is on must match.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=451863&SiteID=1


Show quoteHide quote
"Bmack500" <brett.m***@gmail.com> wrote in message
news:1166732194.589483.318210@a3g2000cwd.googlegroups.com...
> 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
>
Author
21 Dec 2006 9:58 PM
Bmack500
Could you elaborate? Match in what way? Sorry, I'm diving head first
into multithreading; waiting for some books to arrive!

vbnetdev wrote:
Show quoteHide quote
> Your calling thread and thread it is on must match.
>
> http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=451863&SiteID=1
>
>
> "Bmack500" <brett.m***@gmail.com> wrote in message
> news:1166732194.589483.318210@a3g2000cwd.googlegroups.com...
> > 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
> >
Author
21 Dec 2006 10:02 PM
vbnetdev
Make sure the declaration of the object and the actions that occur with the
object exist in the same thread.


Show quoteHide quote
"Bmack500" <brett.m***@gmail.com> wrote in message
news:1166738300.143150.43680@a3g2000cwd.googlegroups.com...
> Could you elaborate? Match in what way? Sorry, I'm diving head first
> into multithreading; waiting for some books to arrive!
>
> vbnetdev wrote:
>> Your calling thread and thread it is on must match.
>>
>> http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=451863&SiteID=1
>>
>>
>> "Bmack500" <brett.m***@gmail.com> wrote in message
>> news:1166732194.589483.318210@a3g2000cwd.googlegroups.com...
>> > 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
>> >
>
Author
22 Dec 2006 12:03 AM
Bmack500
Any chance you could provide a quick example? Sorry, I hate to
impose....

vbnetdev wrote:
Show quoteHide quote
> Make sure the declaration of the object and the actions that occur with the
> object exist in the same thread.
>
>
> "Bmack500" <brett.m***@gmail.com> wrote in message
> news:1166738300.143150.43680@a3g2000cwd.googlegroups.com...
> > Could you elaborate? Match in what way? Sorry, I'm diving head first
> > into multithreading; waiting for some books to arrive!
> >
> > vbnetdev wrote:
> >> Your calling thread and thread it is on must match.
> >>
> >> http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=451863&SiteID=1
> >>
> >>
> >> "Bmack500" <brett.m***@gmail.com> wrote in message
> >> news:1166732194.589483.318210@a3g2000cwd.googlegroups.com...
> >> > 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
> >> >
> >
Author
22 Dec 2006 2:43 AM
vbnetdev
Zip and send me your project and I will see what I can do.


Show quoteHide quote
"Bmack500" <brett.m***@gmail.com> wrote in message
news:1166745806.195146.190780@48g2000cwx.googlegroups.com...
> Any chance you could provide a quick example? Sorry, I hate to
> impose....
>
> vbnetdev wrote:
>> Make sure the declaration of the object and the actions that occur with
>> the
>> object exist in the same thread.
>>
>>
>> "Bmack500" <brett.m***@gmail.com> wrote in message
>> news:1166738300.143150.43680@a3g2000cwd.googlegroups.com...
>> > Could you elaborate? Match in what way? Sorry, I'm diving head first
>> > into multithreading; waiting for some books to arrive!
>> >
>> > vbnetdev wrote:
>> >> Your calling thread and thread it is on must match.
>> >>
>> >> http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=451863&SiteID=1
>> >>
>> >>
>> >> "Bmack500" <brett.m***@gmail.com> wrote in message
>> >> news:1166732194.589483.318210@a3g2000cwd.googlegroups.com...
>> >> > 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
>> >> >
>> >
>
Author
22 Dec 2006 5:40 AM
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

Show quoteHide quote
"Bmack500" <brett.m***@gmail.com> schreef in bericht
news:1166745806.195146.190780@48g2000cwx.googlegroups.com...
> Any chance you could provide a quick example? Sorry, I hate to
> impose....
>
> vbnetdev wrote:
>> Make sure the declaration of the object and the actions that occur with
>> the
>> object exist in the same thread.
>>
>>
>> "Bmack500" <brett.m***@gmail.com> wrote in message
>> news:1166738300.143150.43680@a3g2000cwd.googlegroups.com...
>> > Could you elaborate? Match in what way? Sorry, I'm diving head first
>> > into multithreading; waiting for some books to arrive!
>> >
>> > vbnetdev wrote:
>> >> Your calling thread and thread it is on must match.
>> >>
>> >> http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=451863&SiteID=1
>> >>
>> >>
>> >> "Bmack500" <brett.m***@gmail.com> wrote in message
>> >> news:1166732194.589483.318210@a3g2000cwd.googlegroups.com...
>> >> > 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
>> >> >
>> >
>