[Solved] Cannot create ActiveX component in Vb.net

Hi Friends,
                
Today I'll tell you how to solve "ActiveX component can't create object" Exception in VB.net. You can use the same logic in any other application also.

So I'm getting the this exception when I try to create a obect of  Internet Explorer. When creting the object for first time, it works fine, I can see the given link in the browser, but for second time if I again create the object I got this error.

Here is the code :

Dim browser As Object = CreateObject("InternetExplorer.Application")
browser = CreateObject("InternetExplorer.Application")
And I'm getting the Cannot create ActiveX component error.




So I searched and find a solution, and it is working like charm. Here is the solution.

Dim browser As Object = CreateObject("InternetExplorer.Application")
Try
   browser = CreateObject("InternetExplorer.Application")
Catch ex As Exception
    For Each explorer_process As Process In Process.GetProcesses 
        If String.Compare(explorer_process.ProcessName, "iexplore", True) = 0 Then 
            Try 
                explorer_process.Kill() 
            Catch exp As Exception 
                Exit For 
            End Try 
        End If 
    Next 
    browser = Nothing     
    browser = CreateObject("InternetExplorer.Application")
End Try

Enjoy :)


6 comments:

  1. thanks bro solved my problem

    ReplyDelete
  2. out of box logic great

    ReplyDelete
  3. It errors on TheBrowser because it is not defined

    ReplyDelete
    Replies
    1. Thanks for pointing out the typo error. I have updated the code.

      Delete

 

Pro

About