0

The purpose of this post is to discuss on a topic that I find rather abstract. There will be no reproductible example, unfortunately, but I am curious if there is anyone here who encountered this previously, as well as some tips on what could be going on. Hopefully the things stated below will be enough for you to make an overall idea.

While writing some unit tests, I noticed something that's going on and makes the tests fail. When debbuging I noticed that an object, Properties, is basically null due to having "Could not evaluate expression" when hovering the mouse over it. This causes the program to consider it a null, thus making the tests fail.

I took into considerations all possible causes code-wise, then I thought it might be a problem with Visual Studio's debugging settings, only to find out that it's because of an assembly which that object was imported from.

This assembly is loaded into the project like this:

<Reference Include="Connectivity.DataModel, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
  <HintPath>..\..\..\..\..\..\_external\nuget\nes\Connectivity.DataModel.1.0.0\lib\netstandard2.0\Connectivity.DataModel.dll</HintPath>
</Reference>

I noticed that in another project, the Connectivity.DataModel.dll is referenced as a NuGet and not as an assembly. Therefore, I changed the code above to this:

<ItemGroup>
  <PackageReference Include="Connectivity.DataModel" Version="1.0.0" />
</ItemGroup>

Which finally made the object Properties work as intended.

What is weird only comes now - so after replacing the first code with the second, I ran the application, made sure the tests pass and then decided to undo this change, as, in theory, it should have worked anyways. After reverting back to how it was referenced previously, I was surprised to find out that it STILL works - basically what previously would prompt me that "Could not evaluate expression" error message, now worked.

What could be going on? Why would it work after referencing it as a NuGet and running the code once? The weirdest part now is that I am not able to replicate the issue without getting a brand new copy of this project off git.

Thank you in advance for any piece of advice!

  • There are a variety of reasons you would get that error message in the debugger. Some are transient, some are not. See duplicate. – Peter Duniho Apr 16 '21 at 06:45
  • Thanks but it has nothing to do with that post. I have already seen that one and I will quote myself: `I took into considerations all possible causes code-wise, then I thought it might be a problem with Visual Studio's debugging settings, only to find out that it's because of an assembly which that object was imported from.` Please remove that flag because it has nothing to do with the "duplicate" –  Apr 16 '21 at 06:47
  • I would also highly appreciate if you also opened the post once again. It is really frustrating and I am sure you wouldn't have done it if the title would've been different. –  Apr 16 '21 at 06:50
  • Congratulations. You found one of the transient scenarios, one which is fixed after you force some behind-the-scenes cached state to update by your change, even when you revert the change. That's not different from the general admonition found in other answers. If you feel you've found some new scenario that needs inclusion, feel free to post that as an answer to the duplicate. Otherwise, I disagree that this question is in any material way different from the duplicate. – Peter Duniho Apr 16 '21 at 06:52
  • What an honor! The thing is, I still need answers as to what could be happening in my case and how can I permanently fix it, as the current "fix" is not wanted. I understand that this could be part of the other thread and most probably will after I have more answers than questions. I am really interested on how to force these behind-the-scenes things without actually changing the initial reference, or changing it slightly. At least concept-wise, as I can understand this issue might be a bit hard to grasp without one actually having the source project if front of their eyes. –  Apr 16 '21 at 06:59

0 Answers0