简体   繁体   中英

NotSupportedException was unhandled by user code exception

I'am trying to store a value of Document.cookie into a string variable in my c# code. The idea here is to go through each tab in an Internet Explorer browser and then get the cookie information from the tab. So I have got the following,

ShellWindows iExplorerInstances = new ShellWindows();
                            bool found = false;
                            foreach (InternetExplorer iExplorer in       iExplorerInstances)
                        {
                            if (iExplorer.Name == "Internet Explorer")
                            {
                                string cookie = iExplorer.Document.cookie;

Now this works upon initial running of the code, but when it is run in the same session again it fails and hits NotSupportDeskException on the last line of code above, which is where the string cookie is declared and initialised (line 134). Is there a way around this?

The stack trace is as follows, at System.Dynamic.ComRuntimeHelpers.CheckThrowException(Int32 hresult, ExcepInfo& excepInfo, UInt32 argErr, String message) at CallSite.Target(Closure , CallSite , ComObject ) at CallSite.Target(Closure , CallSite , Object ) at hhsoutlookadin.ThisAddIn.d__3.MoveNext() in Somefile.cs:line 134. The message is "Exception from HRESULT: 0x800A01B6".

I thought this be something to do with casting the Document.cookie object as a string, this appeared to be causing issues after running through the code once. So the Document object I now parse as a mshtml.IHTML2Document2 object. I then make a reference to it cookie object by storing it in a string, which works and doesnt cause any issues.

ShellWindows iExplorerInstances = new ShellWindows();
                        bool found = false;
                        foreach (InternetExplorer iExplorer in iExplorerInstances)
                        {
                            if (iExplorer.Name == "Internet Explorer")
                            {
                                string[] cookieCrumbs = { };
                                try
                                {
                                    mshtml.IHTMLDocument2 htmlDoc = iExplorer.Document as mshtml.IHTMLDocument2;
                                    string cookie = htmlDoc.cookie;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM