NSubstitute
NSubstitute copied to clipboard
Problem inspecting substitute in debugger (function evaluation requires all threads to run)
If I try to inspect a substitute's properties in the debugger I get the message 'The function evaluation requires all threads to run'. If I then click the 'Refresh' button to execute the getter I get the exception:
error CS0234: The type or namespace name 'IMyInterfaceProxy' does not exist in the namespace 'Castle.Proxies' (are you missing an assembly reference?)
To see if this is a problem with Castle Dynamic Proxy I experimented with some of my own code which creates interface proxies directly using Castle.Core, and they work fine in the debugger.
Any clue what is going on here?
NSub: 1.9.2.0 The is using VS2017RC, but I think same in VS2015 too.
Hi Jack, Thanks for checking Dynamic Proxy first. Is this with dotnet core? I don't have any problems debugging substitutes in NET45 with VS2015, but I haven't tried dotnet core.
No, this is with a regular .NET 4.5.2 project. Just updated to NSub 1.10 and still the same problem.
Just checked a few other unit test projects and interfaces. Seem to have the same problem in the debugger.
Strangely the substitutes are still working during normal execution - my tests pass!
I wonder if it is something specific to your project? Can you post a small repro?
If I inspect substitutes in VS I can see all the internals (NSubstitute CallRouter instance, interceptors etc).
More interesting observations:
- Usually a delay when I first hover over the variable or inspect a property value.
- Seems "intermittent" i.e. Time seems to affect things. For example I just failed to view a property, but while typing this reply I switched back to debug sessions and ... I can see the property value. Very strange.
- Seems it doesn't fail on all properties. Sometimes the first two properties fail, but the rest display OK. Inspect again and all work.
- Some of the types referenced on the proxied interface are from a .NET Standard 1.1 project. Not sure if that's relevant.
I can always see the internals e.g. __interceptors, __target etc.
Confirmed apparently same behavior between VS2015 and VS2017. I'm debugging using Resharper NUnit test runner 2016.3
It seems once the substitute has been "used" by a piece of code, then the debugger can view the properties just fine. It's as if something about the VS thread used to execute the getter is failing for some reason, but the test runner thread can get the properties successfully.
I also see two, apparently identical, 'DynamicProxyGenAssembly2' loaded in the Modules. Is two Modules with same name expected??
Using a different test runner seems to make no difference.