2012-02-16 176 views
16

固定的ObjectDisposedException当编辑XAML文件,我注意到以下错误:调试和Visual Studio 2010中

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

要调试这个我跑视觉工作室的另一个实例,“调试 - >附加到进程”的显示异常的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中,和你是做什么来解决它。

+2

澄清,这是Visual Studio中的错误,而不是代码中的错误? – mydogisbox 2012-02-20 16:29:20

+0

您是否能够在发生这种情况时提供XAML? – Phil 2012-02-20 16:45:46

+1

对..它发生在VS2010中。这会导致XAML文件编辑速度变慢,并且VS有时无法响应。双击例外只会导致文件的顶部,没有别的。 – jmogera 2012-02-20 16:47:09

回答

2

您是否运行XAML美化工具? - 我有一些类似的扩展清理XAML。

+0

嗯。谢谢,我会尝试。 – jmogera 2012-05-17 18:23:02

1

这发生在我身上时,我通过编辑.csproj文件手动分组.xaml.cs和.xaml文件。修复此问题I:

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

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