在 Visual Studio 2010 中调试和修复 ObjectDisposeException

发布于 2025-01-06 11:27:40 字数 1623 浏览 1 评论 0原文

编辑 XAML 文件时,我注意到以下错误:

System.ObjectDisposedException occurred
  Message=Cannot access a disposed object.
Object name: 'FileCodeModel'.

为了调试此错误,我运行了 Visual Studios 的另一个实例,并对显示异常的 Visual Studio 实例“调试 -> 附加到进程”。

我能够捕获附加到该进程的启动的新实例中的异常。我捕获了以下异常:

System.ObjectDisposedException occurred
  Message=Cannot access a disposed object.
Object name: 'FileCodeModel'.
  Source=Microsoft.VisualStudio.CSharp.Services.Language
  ObjectName=FileCodeModel
  StackTrace:
       at Microsoft.VisualStudio.CSharp.Services.Language.CodeModel.CFileCodeModel.GetCompilation(Boolean fBlockForParses)
       at Microsoft.VisualStudio.CSharp.Services.Language.CodeModel.CPartialTypeCollection.EnumerateParts()
       at Microsoft.VisualStudio.CSharp.Services.Language.CodeModel.CPartialTypeCollection.get_Count()
       at Microsoft.VisualStudio.CSharp.Services.Language.CodeModel.CSlowSnapshot..ctor(CodeElements collection)
       at Microsoft.VisualStudio.CSharp.Services.Language.CodeModel.CPartialTypeCollection.CreateSnapshot()
       at Microsoft.VisualStudio.CSharp.Services.Language.CodeModel.CCollectionBase.GetEnumerator()
       at EnvDTE.CodeElements.GetEnumerator()
       at MS.Internal.VSSymbols.SymbolProvider.GetProperties(String fullName, Boolean isTypeDefinition, Boolean useCodeModel)
       at Microsoft.Xaml.Symbols.IXamlSymbols.GetProperties(String typeName, Boolean isTypeDefinition, Boolean useCodeModel)
       at MS.Internal.Design.Markup.HostedType.BuildProperties(Boolean useCodeModel)
  InnerException: 

任何人都曾在 XAML 中遇到此异常,以及您如何修复它。

When editing a XAML file I noticed the following error:

System.ObjectDisposedException occurred
  Message=Cannot access a disposed object.
Object name: 'FileCodeModel'.

To debug this I ran another instance of Visual Studios and "Debug-> Attach to Process" to the instance of visual studio where the exception was shown.

I was able to catch the exception in the new Instances that started that is attached to the process. I catch the following exception:

System.ObjectDisposedException occurred
  Message=Cannot access a disposed object.
Object name: 'FileCodeModel'.
  Source=Microsoft.VisualStudio.CSharp.Services.Language
  ObjectName=FileCodeModel
  StackTrace:
       at Microsoft.VisualStudio.CSharp.Services.Language.CodeModel.CFileCodeModel.GetCompilation(Boolean fBlockForParses)
       at Microsoft.VisualStudio.CSharp.Services.Language.CodeModel.CPartialTypeCollection.EnumerateParts()
       at Microsoft.VisualStudio.CSharp.Services.Language.CodeModel.CPartialTypeCollection.get_Count()
       at Microsoft.VisualStudio.CSharp.Services.Language.CodeModel.CSlowSnapshot..ctor(CodeElements collection)
       at Microsoft.VisualStudio.CSharp.Services.Language.CodeModel.CPartialTypeCollection.CreateSnapshot()
       at Microsoft.VisualStudio.CSharp.Services.Language.CodeModel.CCollectionBase.GetEnumerator()
       at EnvDTE.CodeElements.GetEnumerator()
       at MS.Internal.VSSymbols.SymbolProvider.GetProperties(String fullName, Boolean isTypeDefinition, Boolean useCodeModel)
       at Microsoft.Xaml.Symbols.IXamlSymbols.GetProperties(String typeName, Boolean isTypeDefinition, Boolean useCodeModel)
       at MS.Internal.Design.Markup.HostedType.BuildProperties(Boolean useCodeModel)
  InnerException: 

Anybody ever run into this exception in your XAML, and what do you do to fix it.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泅人 2025-01-13 11:27:40

您是否正在运行 XAML 美化器? - 我有类似的东西,有一个清理 XAML 的扩展。

Are you running a XAML beautifier? - I've had something similar with an extension that cleans XAML up.

咋地 2025-01-13 11:27:40

当我通过编辑 .csproj 文件手动对 .xaml.cs 和 .xaml 文件进行分组时,就发生了这种情况。要解决此问题,我:

  1. 将 .xaml 文件移动到不同的文件夹。
  2. 打开解决方案。
  3. 从项目中删除了 .xaml。
  4. 在 Visual Studio 中重新创建 .xaml 文件。
  5. 将原始 .xaml 的内容复制到新创建的 .xaml 中。

按照这些步骤操作后,我不再收到该错误消息。

This happened to me when I manually grouped a .xaml.cs and .xaml file by editing the .csproj file. To fix this I:

  1. Moved .xaml file to different folder.
  2. Opened up solution.
  3. Removed .xaml from project.
  4. Re-created .xaml file in Visual Studio.
  5. Copied the contents of my original .xaml into the newly created .xaml.

After following these steps I no longer got that error message.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文