Wpf 在Visual Studio 2010中调试和修复ObjectDisposedException

Wpf 在Visual Studio 2010中调试和修复ObjectDisposedException,wpf,visual-studio-2010,debugging,xaml,exception,Wpf,Visual Studio 2010,Debugging,Xaml,Exception,编辑XAML文件时,我注意到以下错误: System.ObjectDisposedException occurred Message=Cannot access a disposed object. Object name: 'FileCodeModel'. 为了调试这个,我运行了另一个VisualStudio实例,并将“debug->attachtoprocess”添加到显示异常的VisualStudio实例 我能够在附加到流程的新实例中捕获异常。我发现以下异常: System.Obj

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

System.ObjectDisposedException occurred
  Message=Cannot access a disposed object.
Object name: 'FileCodeModel'.
为了调试这个,我运行了另一个VisualStudio实例,并将“debug->attachtoprocess”添加到显示异常的VisualStudio实例

我能够在附加到流程的新实例中捕获异常。我发现以下异常:

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中都会遇到此异常,您会如何修复它。

您正在运行XAML美化程序吗?-我在清理XAML的扩展名时遇到了类似的情况。

当我通过编辑.csproj文件手动将.XAML.cs和.XAML文件分组时,我遇到了这种情况。要解决此问题,请执行以下操作:

  • 已将.xaml文件移动到其他文件夹
  • 打开了解决方案
  • 已从项目中删除.xaml
  • 在Visual Studio中重新创建.xaml文件
  • 将原始.xaml的内容复制到新创建的.xaml中

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

    为了澄清,这是visual studio中的错误,而不是代码中的错误?您是否能够提供发生这种情况的XAML?是的。。它发生在VS2010年。这会导致XAML文件编辑速度减慢,VS有时会变得无响应。双击异常只会导致文件的顶部,而不会导致其他内容。请将此内容发布到connect.microsoft.com。我现在遇到了这种情况。看起来“FileCodeModel”在XAML语法中使用,突出显示了IDE中使用的文件结构信息。