繁体   English   中英

用户代码异常未处理NotSupportedException

[英]NotSupportedException was unhandled by user code exception

我正在尝试将Document.cookie的值存储到我的C#代码中的字符串变量中。 这里的想法是浏览Internet Explorer浏览器中的每个选项卡,然后从该选项卡获取cookie信息。 所以我得到以下内容

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

现在,这可以在首次运行代码时起作用,但是当它在同一会话中再次运行时,它将失败并在上面的最后一行代码(声明和初始化字符串cookie的位置)(第134行)上命中NotSupportDeskException。 有没有解决的办法?

堆栈跟踪如下,位于System.Dynamic.ComRuntimeHelpers.CheckThrowException(Int32 hresult,ExcepInfo&excepInfo,UInt32 argErr,String消息)位于CallSite.Target(Closure,CallSite,ComObject)的CallSite.Target(Closure,CallSite,Object)在Somefile.cs:第134行的hhsoutlookadin.ThisAddIn.d__3.MoveNext()中。消息为“来自HRESULT的异常:0x800A01B6”。

我认为这与将Document.cookie对象转换为字符串有关,这似乎在遍历代码一次后引起了问题。 因此,我现在将Document对象解析为mshtml.IHTML2Document2对象。 然后,我通过将其存储在字符串中来对它的cookie对象进行引用,该字符串有效且不会引起任何问题。

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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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