jeudi 3 juin 2021

Immediate window evaluates to true while debugging evaluates to false?

I'm loading types from assemblies using reflection:

foreach (string assemblyPath in assemblyPaths) {
    Assembly assembly = Assembly.LoadFrom(assemblyPath);
    if (assembly.GetTypes().Any(a => typeof(IChannel).IsAssignableFrom(a))) {
        DoSomethingCool();
    }
}

When I debug this code, I stop at the logical evaluation with a breakpoint, and check the answer in the immediate window, which evaluates to true:

screenshot of immediate window

When I continue execution of my code, the block for the if statement never executes, which leads me to assume that it evaluates to false when that line executes. However, I think something wonky is going on that I'm just not seeing.

  • I've tried restarting Visual Studio and my computer, just-in-case it was a software issue.
  • I've tried reversing the logic to a.IsAssignableFrom(typeof(IChannel))1.
  • I've also reviewed the results of .GetTypes() and the type I'm looking for is there.
  • I performed the same check, on the type I'm looking for (.GetTypes()[0]), and it evaluated to true as expected.

1: This evaluates to false in the immediate window and doesn't enter the block, as I'd expect.


What are other reasons that could cause this inconsistency while debugging?





Aucun commentaire:

Enregistrer un commentaire