【问题标题】:Debug and Fixing ObjectDisposedException in Visual Studio 2010在 Visual Studio 2010 中调试和修复 ObjectDisposedException
【发布时间】:2012-03-08 02:12:03
【问题描述】:

在编辑 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 中遇到过此异常,您将如何修复它。

【问题讨论】:

  • 澄清一下,这是 Visual Studio 中的错误,而不是您的代码中的错误?
  • 您能否提供发生这种情况的 XAML?
  • 对.. 它发生在 VS2010 中。这会导致 XAML 文件编辑速度变慢,并且 VS 有时会变得无响应。双击异常只会导致文件的顶部,没有别的。
  • 发布到 connect.microsoft.com
  • 现在发生在我身上。看起来“FileCodeModel”用于 IDE 中使用的 XAML 语法突出显示/文件结构信息。

标签: wpf visual-studio-2010 debugging xaml exception


【解决方案1】:

您是否正在运行 XAML 美化器? - 我在清理 XAML 的扩展中遇到过类似的情况。

【讨论】:

    【解决方案2】:

    当我通过编辑 .csproj 文件手动对 .xaml.cs 和 .xaml 文件进行分组时,这发生在我身上。为了解决这个问题,我:

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

    执行这些步骤后,我不再收到该错误消息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多