0

trying to attach to an IE browser.. it works for awhile then starts throwing this error...

---------------------------

---------------------------
Unable to cast COM object of type 'System.__ComObject' to interface type 'mshtml.HTMLDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{3050F55F-98B5-11CF-BB82-00AA00BDCE0B}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
---------------------------
OK   
---------------------------

this code is fired on a timer of 500 millisecods...

could someone tell me how to fix it?? what I'm doing wrong?? || how I can improve it... My code is as follows...

 try
            {
                ShellWindows shellWindows = new ShellWindows();

                foreach (InternetExplorer ie in shellWindows)
                {
                    HTMLDocument document = ie.Document;

                    if (ie.LocationURL.Contains(ReserveRoomRsa + " ") || ie.LocationURL.Contains(ReserveRoomWww + " "))
                    {
                        if (bCodeScannerConnected && !idScannerShown)
                        {
                            idScannerShown = true;
                            ScanID(ie, "", "", "", "", "", "");
                            ie.Document.All.Item("guestHomePhone").Focus();
                            timer3.Enabled = true;
                        }
                    }
                    else if (ie.LocationURL.Contains(ReserveRoomRsa) || ie.LocationURL.Contains(ReserveRoomWww))
                    {
                        if (bCodeScannerConnected && !idScannerShown)
                        {
                            idScannerShown = true;
                            ScanID(ie, "lastName", "firstName", "homeAddressOne", "homeZip", "homeCity", "homeState");
                            ie.Document.All.Item("guestHomePhone").Focus();
                            timer3.Enabled = true;
                        }

                        DoNotRentAlert(ie.Document);
                    }
                    else if (ie.LocationURL.Contains(FindReservationRsa) || ie.LocationURL.Contains(FindReservationWww))
                    {
                        DoNotRentAlert(ie.Document);
                    }
                }
            }
            catch (Exception err)
            {
                if (i == 0)
                {
                    i += 1;
                    MessageBox.Show(err.Message);
                }
            }

NOTE TO SELF: Why do I need more details?? the Source Code is WAY MORE DETAILS than a PROGRAMMER Wants to give out when writing the next million dollar app!

  • 1
    All COM objects need to be released via `Marshal.ReleaseComObject`. Relying on the garbage collector to release them is a bad idea. This applies to any temporary objects like `B` in `A.B.C`. – Jeremy Lakeman Jul 27 '20 at 01:07
  • Since these objects will hand around and the garbage collector will destroy them in a random order, what you've written is essentially a fuzz tester of all those COM object destructors. Stress testing the COM interfaces in a way that Microsoft doesn't expect anyone to do. – Jeremy Lakeman Jul 27 '20 at 01:14
  • ok so what's the recommended way of doing it? basically the hotel check in process is done through internet explorer.. my app has to constantly check to see if the website is the exact one then popup my IDScanner form to allow us to scan the barcode on the back of the guests drivers license. – Christopher Workman Jul 27 '20 at 01:39
  • 1
    You should be able to add event listeners to detect page loads and reduce the volume of com api calls. But you will still need to manage the lifetime of each temporary com object in statements like `ie.Document.All.Item("guestHomePhone").Focus()`. – Jeremy Lakeman Jul 27 '20 at 02:01
  • I would also consider some form of javascript injection to hook the control focus events, or add extra controls into the html. – Jeremy Lakeman Jul 27 '20 at 02:03
  • I think you should use any other logic instead of continuously checking the opened website in the IE. This approach will increase the overhead and lead to this error. I am not sure how exactly your app works. If possible then you can try to launch that website from your code then it might be easy to handle it. – Deepak-MSFT Jul 27 '20 at 08:25
  • Thanks Jeremy Lakeman! I ended up using IE document complete events... basically I still have a timer ticking @ 500 Milliseconds... Once it finds an IE window that timer is then stopped.. After the page loads to the correct URL it enables a timer so that it can fill in guest info from the barcode scanner & determine whether the guest is on the do not rent list after which it then turns itself off until loaded again in the future.. if the IE browser is closed the timer will turn back on to look for another IE window to attach to.. – Christopher Workman Jul 27 '20 at 10:34
  • Thanks for sharing the solution to the issue. I suggest you post your solution as an answer for this thread and try to mark your own answer as an answer to this question after 48 hrs when it is available to mark. It can help other community members in the future in similar kinds of issues. Thanks for your understanding – Deepak-MSFT Jul 29 '20 at 09:36

0 Answers0