简体   繁体   English

用户代码异常未处理NotSupportedException

[英]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. 我正在尝试将Document.cookie的值存储到我的C#代码中的字符串变量中。 The idea here is to go through each tab in an Internet Explorer browser and then get the cookie information from the tab. 这里的想法是浏览Internet Explorer浏览器中的每个选项卡,然后从该选项卡获取cookie信息。 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). 现在,这可以在首次运行代码时起作用,但是当它在同一会话中再次运行时,它将失败并在上面的最后一行代码(声明和初始化字符串cookie的位置)(第134行)上命中NotSupportDeskException。 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". 堆栈跟踪如下,位于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”。

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. 我认为这与将Document.cookie对象转换为字符串有关,这似乎在遍历代码一次后引起了问题。 So the Document object I now parse as a mshtml.IHTML2Document2 object. 因此,我现在将Document对象解析为mshtml.IHTML2Document2对象。 I then make a reference to it cookie object by storing it in a string, which works and doesnt cause any issues. 然后,我通过将其存储在字符串中来对它的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