用户代码异常未处理NotSupportedException [英] NotSupportedException was unhandled by user code exception

查看:265
本文介绍了用户代码异常未处理NotSupportedException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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;

现在,此功能在代码首次运行时有效,但是在同一会话中再次运行时失败并在上面代码的最后一行命中NotSupportDeskException,这是声明和初始化字符串cookie的位置(第134行)。可以解决这个问题吗?

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?

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

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".

推荐答案

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

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;

这篇关于用户代码异常未处理NotSupportedException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆