Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio IDE error - Cannot access a disposed object

I'm getting the following error when trying to open any .cs file in my solution.

enter image description here

I've tried 1) restarting Visual Studio, 2) restarting computer, 3) delete all obj folders, 4) delete all .vs files and folders and still I can't open any files.

Same error message if I double click on the file in solution explorer or use F7.

The files do exist.

I've also tried disabling resharper in case it was that causing the issues, but it doesn't help.

I've also tried navigating to classes using Ctrl+T, entering class name and selecting the class. No error messages, but nothing loads.

like image 435
Stuart Avatar asked Oct 22 '17 11:10

Stuart


People also ask

What does Cannot access a disposed object mean?

: 'Cannot access a disposed object. A common cause of this error is disposing a context that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application.

What is disposed object in C#?

In the context of C#, dispose is an object method invoked to execute code required for memory cleanup and release and reset unmanaged resources, such as file handles and database connections.


Video Answer


1 Answers

This is the error I got when I tried to open an old solution: Cannot access a disposed object. Object name: 'WorkspaceContext'. I found the solution from Refat Eid's blog.

You just need to open the following directory and delete the content there: %LocalAppData%\Microsoft\Team Foundation\7.0\Cache

Depending on your Visual Studio, you may have a different version number in your %LocalAppData%\Microsoft\Team Foundation. If you are not sure, copy the content to a temp folder first.

Other answers, either upgrading or reinstalling, basically serve the same purpose.

like image 104
Weihui Guo Avatar answered Sep 21 '22 15:09

Weihui Guo