Here is the error
Cannot evaluate expression because a thread is stopped at a point where garbage collection is impossible, possibly because the code
I got this too, when I hit a NullReferenceException
from a 3rd party control.
In this one case, I found that if I set a breakpoint before I hit the exception, I could then single step through the rest of the code without seeing the problem.
No idea why, but this worked for me - in this case at least.
If your project is compiled in release (with optimizations turned on), you may see this. Have you tried the DEBUG configuration?
This error fires only when you are trying to use Watch
dialog during debug.
Try to use some other technique to output the variables, like Debug.WriteLine
, Console.WriteLine
and so on.
None of the answers solved my problem so I'm posting the solution that helped me.
"If there is to much data in the parameters then this error can occure, a simple solution is to make an object, not a struct because that's a dataobject.
Put this object in your parameters instead of all the different variables, normally the problem will no longer take place."
First make sure that you're running your code in DEBUG mode and with code optimization turned off. you can turn that off from the properties of your project.
If you made all of the above and the problem persists, then it's probably a problem with the stack having Debug.Break()
on top of it. The solution for this is very easy, just press F10
to move to the next line and you should be able to evaluate the expression.
You can check this SO question for more information about this issue.