![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | False IE doc body error - "Object reference not set to an instance of an object" I go through the process of getting a legitimate reference to Internet Explorer, but then can't get a legitimate document body reference for automatic display. Why not? It appears that I really AM getting an object reference. Here's an example. PS> $ie = New-Object -ComObject InternetExplorer.Application PS> $ie.Navigate("http://www.google.com") PS> $ie.Visible = $true PS> $ie.document.body format-default : Object reference not set to an instance of an object. Let's be more direct. The following ends up giving us an immense member listing: PS> $body = $ie.document.body PS> $body | gm TypeName: mshtml.HTMLBodyClass Name ... However, if we try to just show the body, we still get the spurious error message: PS> $body format-default : Object reference not set to an instance of an object. Note that we can see properties of $body as well; for example, $body.innerText shows us the actual page display text. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: False IE doc body error - "Object reference not set to an instance of an object" The problem is specific to this COM object, PowerShell can't enumerate the following collections. filters IHTMLElement_filters -- Yuksel Akinci [MSFT] Windows PowerShell Team Microsoft Corporation This posting is provided "AS IS" with no warranties, and confers no rights. Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scr.../hubs/msh.mspx "Alex K. Angelopoulos [MVP]" <aka@online.mvps.org> wrote in message news:O1PPFTspGHA.2256@TK2MSFTNGP03.phx.gbl... >I go through the process of getting a legitimate reference to Internet >Explorer, but then can't get a legitimate document body reference for >automatic display. Why not? It appears that I really AM getting an object >reference. > > Here's an example. > > PS> $ie = New-Object -ComObject InternetExplorer.Application > PS> $ie.Navigate("http://www.google.com") > PS> $ie.Visible = $true > PS> $ie.document.body > format-default : Object reference not set to an instance of an object. > > Let's be more direct. The following ends up giving us an immense member > listing: > > PS> $body = $ie.document.body > PS> $body | gm > TypeName: mshtml.HTMLBodyClass > > Name ... > > However, if we try to just show the body, we still get the spurious error > message: > > PS> $body > format-default : Object reference not set to an instance of an object. > > Note that we can see properties of $body as well; for example, > $body.innerText shows us the actual page display text. > > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: False IE doc body error - "Object reference not set to an instance of an object" I also wanted to play with IE from PowerShell. Bumped into so many bumps that I have to choose a different language for that. COM support is problematic in VBScript as well. I tried to cancel navigation from BeforeNavigate2 Event by setting Cancel to true, but that would never work. It behaves as if in VBScript, COM parameters are always ByVal even if they are defined as OUT params in COM. I asked Eric Lippert about that, but never got anything back from him on this. Documentation seem to never mention this aspect. Greg "Alex K. Angelopoulos [MVP]" <> wrote in message news:O1PPFTspGHA.2256@TK2MSFTNGP03.phx.gbl... >I go through the process of getting a legitimate reference to Internet >Explorer, but then can't get a legitimate document body reference for >automatic display. Why not? It appears that I really AM getting an object >reference. > > Here's an example. > > PS> $ie = New-Object -ComObject InternetExplorer.Application > PS> $ie.Navigate("http://www.google.com") > PS> $ie.Visible = $true > PS> $ie.document.body > format-default : Object reference not set to an instance of an object. > > Let's be more direct. The following ends up giving us an immense member > listing: > > PS> $body = $ie.document.body > PS> $body | gm > TypeName: mshtml.HTMLBodyClass > > Name ... > > However, if we try to just show the body, we still get the spurious error > message: > > PS> $body > format-default : Object reference not set to an instance of an object. > > Note that we can see properties of $body as well; for example, > $body.innerText shows us the actual page display text. > > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: False IE doc body error - "Object reference not set to an instance of an object" Are you familiar with the technical issues behind this problem? That's what I'm really interested in. We have the same problem with MANY different method calls, most commonly involving enumerations and HTML docs. Unfortunately, they tend to be show-stoppers for many truly useful automation activities. ![]() "Yuksel Akinci [MSFT]" <yuksela@microsoft.com> wrote in message news:OlUxDAtpGHA.3324@TK2MSFTNGP05.phx.gbl... > The problem is specific to this COM object, PowerShell can't enumerate the > following collections. > > filters > IHTMLElement_filters > > > -- > Yuksel Akinci [MSFT] > Windows PowerShell Team > Microsoft Corporation > This posting is provided "AS IS" with no warranties, and confers no > rights. > > Visit the Windows PowerShell Team blog at: > http://blogs.msdn.com/PowerShell > Visit the Windows PowerShell ScriptCenter at: > http://www.microsoft.com/technet/scr.../hubs/msh.mspx > "Alex K. Angelopoulos [MVP]" <aka@online.mvps.org> wrote in message > news:O1PPFTspGHA.2256@TK2MSFTNGP03.phx.gbl... >>I go through the process of getting a legitimate reference to Internet >>Explorer, but then can't get a legitimate document body reference for >>automatic display. Why not? It appears that I really AM getting an object >>reference. >> >> Here's an example. >> >> PS> $ie = New-Object -ComObject InternetExplorer.Application >> PS> $ie.Navigate("http://www.google.com") >> PS> $ie.Visible = $true >> PS> $ie.document.body >> format-default : Object reference not set to an instance of an object. >> >> Let's be more direct. The following ends up giving us an immense member >> listing: >> >> PS> $body = $ie.document.body >> PS> $body | gm >> TypeName: mshtml.HTMLBodyClass >> >> Name ... >> >> However, if we try to just show the body, we still get the spurious error >> message: >> >> PS> $body >> format-default : Object reference not set to an instance of an object. >> >> Note that we can see properties of $body as well; for example, >> $body.innerText shows us the actual page display text. >> >> > > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: False IE doc body error - "Object reference not set to an instance of an object" It's a pain to do because of the weird compatibility rules with VBScript byref calls that vary depending on number of args, arrayness, and consuming a return value, but I've pretty much always been able to get byref values back. The sad thing is that PowerShell really DID work nicely with IE in 2004 and early 2005. ![]() "Greg Borota" <borota@newsgroups.microsoft> wrote in message news:u%23uSFutpGHA.1600@TK2MSFTNGP04.phx.gbl... >I also wanted to play with IE from PowerShell. Bumped into so many bumps >that I have to choose a different language for that. > > COM support is problematic in VBScript as well. I tried to cancel > navigation from BeforeNavigate2 Event by setting Cancel to true, but that > would never work. It behaves as if in VBScript, COM parameters are always > ByVal even if they are defined as OUT params in COM. I asked Eric Lippert > about that, but never got anything back from him on this. Documentation > seem to never mention this aspect. > > Greg > > "Alex K. Angelopoulos [MVP]" <> wrote in message > news:O1PPFTspGHA.2256@TK2MSFTNGP03.phx.gbl... >>I go through the process of getting a legitimate reference to Internet >>Explorer, but then can't get a legitimate document body reference for >>automatic display. Why not? It appears that I really AM getting an object >>reference. >> >> Here's an example. >> >> PS> $ie = New-Object -ComObject InternetExplorer.Application >> PS> $ie.Navigate("http://www.google.com") >> PS> $ie.Visible = $true >> PS> $ie.document.body >> format-default : Object reference not set to an instance of an object. >> >> Let's be more direct. The following ends up giving us an immense member >> listing: >> >> PS> $body = $ie.document.body >> PS> $body | gm >> TypeName: mshtml.HTMLBodyClass >> >> Name ... >> >> However, if we try to just show the body, we still get the spurious error >> message: >> >> PS> $body >> format-default : Object reference not set to an instance of an object. >> >> Note that we can see properties of $body as well; for example, >> $body.innerText shows us the actual page display text. >> >> > > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: False IE doc body error - "Object reference not set to an inst I thought that is was a general rule - no ByRef from COM in VBScript. Thanks for confirming the opposite. But still this doesn't hold for BeforeNavigate2. I've seen other people on the web complaining about this too (but no solution) - setting Cancel to true in your BeforeNavigate2 handler has no effect - the navigation goes ahead undisturbed. But that's OT for this list, so I'll stop here Greg "Alex K. Angelopoulos [MVP]" wrote: > It's a pain to do because of the weird compatibility rules with VBScript > byref calls that vary depending on number of args, arrayness, and consuming > a return value, but I've pretty much always been able to get byref values > back. > > The sad thing is that PowerShell really DID work nicely with IE in 2004 and > early 2005. ![]() > > "Greg Borota" <borota@newsgroups.microsoft> wrote in message > news:u%23uSFutpGHA.1600@TK2MSFTNGP04.phx.gbl... > >I also wanted to play with IE from PowerShell. Bumped into so many bumps > >that I have to choose a different language for that. > > > > COM support is problematic in VBScript as well. I tried to cancel > > navigation from BeforeNavigate2 Event by setting Cancel to true, but that > > would never work. It behaves as if in VBScript, COM parameters are always > > ByVal even if they are defined as OUT params in COM. I asked Eric Lippert > > about that, but never got anything back from him on this. Documentation > > seem to never mention this aspect. > > > > Greg > > > > "Alex K. Angelopoulos [MVP]" <> wrote in message > > news:O1PPFTspGHA.2256@TK2MSFTNGP03.phx.gbl... > >>I go through the process of getting a legitimate reference to Internet > >>Explorer, but then can't get a legitimate document body reference for > >>automatic display. Why not? It appears that I really AM getting an object > >>reference. > >> > >> Here's an example. > >> > >> PS> $ie = New-Object -ComObject InternetExplorer.Application > >> PS> $ie.Navigate("http://www.google.com") > >> PS> $ie.Visible = $true > >> PS> $ie.document.body > >> format-default : Object reference not set to an instance of an object. > >> > >> Let's be more direct. The following ends up giving us an immense member > >> listing: > >> > >> PS> $body = $ie.document.body > >> PS> $body | gm > >> TypeName: mshtml.HTMLBodyClass > >> > >> Name ... > >> > >> However, if we try to just show the body, we still get the spurious error > >> message: > >> > >> PS> $body > >> format-default : Object reference not set to an instance of an object. > >> > >> Note that we can see properties of $body as well; for example, > >> $body.innerText shows us the actual page display text. > >> > >> > > > > > > > |
My System Specs![]() |
| | #7 (permalink) |
| | Re: False IE doc body error - "Object reference not set to an inst Greg Borota wrote: > I thought that is was a general rule - no ByRef from COM in VBScript. > Thanks for confirming the opposite. But still this doesn't hold for > BeforeNavigate2. I've seen other people on the web complaining about > this too (but no solution) - setting Cancel to true in your > BeforeNavigate2 handler has no effect - the navigation goes ahead > undisturbed. But that's OT for this list, so I'll stop here A workable BeforeNavigate2 event handler needs to support the bCancel argument as a strongly typed Boolean ByRef and VBScript only supports variants. The OLE automation layer effectively coerces the Boolean ByRef to Variant ByVal. A client language like classic VB/VBA handles the bCancel argument just fine, just not VBScript. -- Michael Harris Microsoft MVP Scripting |
My System Specs![]() |
| | #8 (permalink) |
| | Re: False IE doc body error - "Object reference not set to an inst Thanks for shining the light on this. "Michael Harris (MVP)" wrote: > Greg Borota wrote: > > I thought that is was a general rule - no ByRef from COM in VBScript. > > Thanks for confirming the opposite. But still this doesn't hold for > > BeforeNavigate2. I've seen other people on the web complaining about > > this too (but no solution) - setting Cancel to true in your > > BeforeNavigate2 handler has no effect - the navigation goes ahead > > undisturbed. But that's OT for this list, so I'll stop here > > A workable BeforeNavigate2 event handler needs to support the bCancel > argument as a strongly typed Boolean ByRef and VBScript only supports > variants. The OLE automation layer effectively coerces the Boolean ByRef to > Variant ByVal. A client language like classic VB/VBA handles the bCancel > argument just fine, just not VBScript. > > -- > Michael Harris > Microsoft MVP Scripting > > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Inherit from usercontrol - Object not set to instance of an object | .NET General | |||
| runtime error: "Object required" | VB Script | |||
| datalist -- Object reference not set to an instance of an object. | .NET General | |||
| Error: "Cannot convert "System.Object[]" to "System.Int32"." | PowerShell | |||
| Writing a "good" error object? | PowerShell | |||