7

I am trying to get the inspect the values of local variables. This feature works for some variables. For those that it doesn't, Rider brings up an error:

The name `variable_name` does not exists in the current context.

And image example of code and debugger watch error:

enter image description here enter image description here

This is decompiled code, but even here it works for some local variables. What could be the fix for this?

I already check Settings->Build, Execution, Deployment->Disable JIT optimization on module load (.NET/.NET Core only), but as it says, it only works for .NET/.NET Core modules

sanjihan
  • 5,592
  • 11
  • 54
  • 119
  • 6
    Could be that the assembly was compiled in Release and the variable was optimized away? – Shahafo Oct 27 '19 at 20:04
  • Not sure, I haven't compiled it my self. How can I check? – sanjihan Oct 27 '19 at 20:30
  • Open the assembly in [JustCompile](https://www.telerik.com/products/decompiler.aspx) or [ILSpy](https://github.com/icsharpcode/ILSpy) and look for the [AssemblyConfiguration](https://learn.microsoft.com/en-us/dotnet/api/system.reflection.assemblyconfigurationattribute?view=netframework-4.8) attribute at the assembly level – Shahafo Oct 27 '19 at 20:51
  • Thank you! Indeed the assembly is marked as Release. I have access to the source code for the assembly in question, but it is maintained as a different project. I have compiled the source again in a Debug option. The tricky part is how to replace the .dll file. If I just got to explorer and replace it, I am getting an error that the `The located assembly's manifest definition does not match the assembly reference.` – sanjihan Oct 27 '19 at 21:57
  • It seems there are differences between Debug assembly and the Release assembly. My guess is either the assembly version or the Public Key Token. You can enable [Fusion Log](https://stackoverflow.com/questions/255669/how-to-enable-assembly-bind-failure-logging-fusion-in-net) to see the reason the binding to the new assembly failed. – Shahafo Oct 28 '19 at 06:38
  • Same issue. My project was running in release mode. – SINGULARITY Jun 19 '20 at 19:04

1 Answers1

1

I had the same problem. In my case, the use of Fody was causing the problem, although the assembly was compiled in the Debug mode. After disabling Fody, I could see the variable value while debugging. I thought this might be useful for someone else. Please check if your project is using any IL manipulation tools, such as Fody.

Developer
  • 435
  • 4
  • 16