Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug and Fixing ObjectDisposedException in Visual Studio 2010

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.

like image 602
jmogera Avatar asked Feb 16 '12 16:02

jmogera


People also ask

How do I enable Break on exception in Visual Studio?

Tell the debugger to break when an exception is thrownIn the Exception Settings window (Debug > Windows > Exception Settings), expand the node for a category of exceptions, such as Common Language Runtime Exceptions. Then select the check box for a specific exception within that category, such as System.

How do I enable debugging in Visual Studio 2010?

Immediate Window (Ctrl +D, I) You should first start the application in debugging mode by using F5 and then open this window. This is a shortcut utility to open other debugging windows; for instance, the Breakpoint window by writing '>bl', the call stack window by writing'>callstack', and so on.

How do I reset Visual Studio exceptions?

To set Visual Studio debugger options, select Tools > Options, and under Debugging select or deselect the boxes next to the General options. You can restore all default settings with Tools > Import and Export Settings > Reset all settings.


2 Answers

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

like image 111
BaconSah Avatar answered Sep 29 '22 17:09

BaconSah


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.

like image 25
burnttoast11 Avatar answered Sep 29 '22 17:09

burnttoast11