envdte.dte.documents每次访问时每次都可以访问,

发布于 2025-02-09 05:22:18 字数 990 浏览 0 评论 0原文

我正在尝试存储Visual Studio环境中的打开文档。 该代码适用于某些解决方案,但是我有1个解决方案,它总是会引发异常。 我试图等待某种初始化,但是随着时间的推移没有任何变化。 一旦我发现例外,当我再次致电该物业时,这很好。 我做错了什么?

        internal static IList<Document> GetOpenedDocuments(DTE service)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }

            List<Document> openedDocuments = new List<Document>();

            foreach (Document document in service.Documents)
            {
                if (document != null)
                {
                    openedDocuments.Add(document);
                }
            }

            return openedDocuments;
        }

访问service.documents总是第一次崩溃。 堆栈痕迹的顶部:

在envdte.documents.getEnumerator()

异常消息中:

系统找不到指定的文件。 (Hresult的例外:0x80070002)

感谢您的帮助!

I'm trying to store the opened documents from the Visual Studio environment.
The code works for some solutions but I have 1 solution where it always throws an exception.
I have tried to wait for some kind of initialization but nothing changes over time.
As soon as I catch the exception, when I call the property again it's fine.
What do I do wrong?

        internal static IList<Document> GetOpenedDocuments(DTE service)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }

            List<Document> openedDocuments = new List<Document>();

            foreach (Document document in service.Documents)
            {
                if (document != null)
                {
                    openedDocuments.Add(document);
                }
            }

            return openedDocuments;
        }

Accessing service.Documents always crashes the first time.
Top of stack trace:

at EnvDTE.Documents.GetEnumerator()
at XXX.FileHelper.GetOpenedDocuments(DTE service) in

Exception message:

The system cannot find the file specified. (Exception from HRESULT: 0x80070002)

Thanks for the help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文