簡體   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