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.
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 :)
thanks bro solved my problem
ReplyDeleteout of box logic great
ReplyDeleteIt errors on TheBrowser because it is not defined
ReplyDeleteThanks for pointing out the typo error. I have updated the code.
DeleteThat's great stuff! Thank you very much :)
ReplyDeletewelcome :)
DeleteWouldn't it be better to call GetObject() first, and only call CreateObject() if there isn't an instance already running?
ReplyDeleteProblem with the getObject is that it is already running with old data.
Delete