VB.net Unable to cast COM object of type 'System.__ComObject' to interface type 'Shell32.Shell' -Copy And Replace Files-

0

System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'Shell32.Shell'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{34936BA1-67AD-4C41-99B8-8C12DFF1E974}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

at DisGruntled.Copy_Replace.CopyReplace(Object param) in F:\Copy Replace.vb:line 31

at DisGruntled.Copy_Replace.CopyReplaceFromMTAThread(String Path_copy, String Path_Replace) in F:\Copy Replace.vb:line 70

at DisGruntled.Form3.btnStart_Click(Object sender, EventArgs e) in F:\Form3.vb:line 442

Here Is my Codes in Module(Copy_Replace).vb.vb:

Imports System.Threading
Imports Shell32

Module Copy_Replace

Dim objFolder As Folder
    Dim objShell As Shell
    Public Sub CopyReplace(ByVal param As Object)
        Dim args As Object() = CType(param, Object())
        Dim Path_copy As String = CStr(args(0))
        Dim Path_Replace As String = CStr(args(1))

        objShell = New Shell                                        ' line 31  (Which has Error) ??????

        '1
        objFolder = objShell.NameSpace(Path_Replace)

        If (Not objFolder Is Nothing) Then

            objFolder.CopyHere(Path_copy, 4 + 16)
        End If

        objFolder = Nothing
        objShell = Nothing
    End Sub
 Public Sub CopyReplace(ByVal Path_copy As String, ByVal Path_Replace As String)
        Dim args As Object() = New Object() {Path_copy, Path_Replace}

        If Thread.CurrentThread.GetApartmentState() = ApartmentState.STA Then
            'UnZip(args)
            CopyReplace(args)                                       ' line 70  (Which has Error) ??????
        Else
            Dim staThread1 As Thread = New Thread(New ParameterizedThreadStart(AddressOf CopyReplace))
            staThread1.SetApartmentState(ApartmentState.STA)
            staThread1.Start(args)
            staThread1.Join()
        End If
    End Sub
End Module  

I picked this answer from here and edited it to the code which you can see in my Module(Copy_Replace).vb.

Here is my Button_click code: (in form Class)

Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
        CopyReplaceFromMTAThread(X_path, O_path)  ' line 442  (Which has Error) ??????
End Sub
vb.net
asked on Stack Overflow May 12, 2020 by Eslam Alawy • edited May 12, 2020 by Eslam Alawy

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0