Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Impossible to get rid of NCrunch finding referenced file in wrong cached location
abelb
#1 Posted : Monday, December 19, 2016 6:43:42 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/12/2014(UTC)
Posts: 155
Location: Netherlands

Thanks: 19 times
Was thanked: 11 time(s) in 11 post(s)
This one may be hard to diagnose or repro, but I had the following:


  1. Some existing solution with existing projects having x64, x86 and AnyCPU variants
  2. Added a project (F#), this defaults to AnyCPU
  3. Added NUnit, reference to one of the other projects (project ref) and a dummy test
  4. Configured NCrunch, ran dummy test, all was fine
  5. Added dependent test (dependent on referenced prj) and received BadImageFormatException in NCrunch
  6. Assumed it was caused by missing x86/x64 and the build for NCrunch was x64
  7. Added configurations to project file, added new output locations for project
  8. Fixed NCrunch to use x64 for all projects
  9. Still BadImageFormatException
  10. Reset NCrunch in several ways, restarted NCrunch, restarted VS
  11. Still BadImageFormatException
  12. Checked my own build and loaded it in NUnit runner, success
  13. Checked build dir of NCrunch
  14. Checked the path that NCrunch showed in log for the BadImageFormatException: it didn't exist


The error was as follows (edited to prevent it from stretching the browser window of this forum):

Code:
System.BadImageFormatException : 
Could not load file or assembly 'Lib.Common, Version=1.1.2799.4322, Culture=neutral, PublicKeyToken=null' 
or one of its dependencies. An attempt was made to load a program with an incorrect format.
  ----> System.BadImageFormatException : 
Could not load file or assembly 'file:///C:\Users\Abel\AppData\Local\NCrunch\16416\3\Lib.Common\bin\Debug\x64\Lib.Common.dll' 
or one of its dependencies. An attempt was made to load a program with an incorrect format.
   at Tests.Lib.Common.CommonTests.Str.empty()
--BadImageFormatException


The directory C:\Users\Abel\AppData\Local\NCrunch\16416 didn't exist at all. It referenced the exact same location after restart, after "Reload and rebuild selected component".

Finally, I decided to rename the project, hoping that this would cause NCrunch to stop using its (wrong) temp file locations. This "just worked".

I believe I had something similar a long time ago and my request at the time was to add an option to delete temp files. I think the "reload and rebuild selected component" was meant to work that way, or otherwise the Enable/Disable NCrunch menu (which rebuilds everything). However, this appears to be wrong, at least *something* is still hanging around causing this error (don't be fooled by the BadImageFormatException, it basically means it cannot find the dependency).

Is there a method of deleting temp files that I have missed or is my understanding of the "reload/rebuild" option incorrect (or is it simply a bug?). I may be able to repro since I have a pretty good grasp of the project state this was in, but this will be time-consuming and non-trivial.

I use the latest downloadable public version of NCrunch, v3.2.0.3.

EDIT: I just noticed that if I rename it back, the error re-occurs. So, in case you want me to do some diagnostics, I will keep the situation as is (without trying to force-cleaning everything).

EDIT AGAIN: sorry, after the latest restart of VS the error is gone completely now
Remco
#2 Posted : Monday, December 19, 2016 6:55:48 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 960 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi,

Thanks for sharing this issue.

Are you able to reproduce it then send me a bug report right after it happens? The report might yield something to help narrow this down.

I find it very strange that this error points to the same location between sessions. The 16416 in the file path is derived from the PID of the NCrunch process, which should almost never be the same between instances of the engine. Note that NCrunch DOES preserve error information between sessions. It's worth confirming that you are looking at a newly built project and not an error from the previous session.
Remco
#3 Posted : Monday, December 19, 2016 6:57:01 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 960 times
Was thanked: 1290 time(s) in 1196 post(s)
abelb;9583 wrote:
EDIT AGAIN: sorry, after the latest restart of VS the error is gone completely now


Rats. If you see it again, please do push it through the bug reporter.
abelb
#4 Posted : Monday, December 19, 2016 2:46:26 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/12/2014(UTC)
Posts: 155
Location: Netherlands

Thanks: 19 times
Was thanked: 11 time(s) in 11 post(s)
Sorry, I seem to have forgotten about the bug reporter in VS for NCrunch. Though I am positive that the error + the number of the directory was the same between sessions. I have seen before that NCrunch processes stay around when I close VS, perhaps this is related? I will try to repro though.
abelb
#5 Posted : Monday, December 19, 2016 8:06:08 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/12/2014(UTC)
Posts: 155
Location: Netherlands

Thanks: 19 times
Was thanked: 11 time(s) in 11 post(s)
It turned out that the whole process was reproducible step-by-step. I have sent a Bug Report from VS for almost each step, leading to 6 reports. Number five is the one where renaming the project solves the issue and number six being where renaming it back unsolves it (i.e., raises the original error again). I also included the report after restarting VS (number four), after re-enabling NCrunch (number three), the correct configuration but with error (number two), the incorrect configuration with error (number one).

Here is a visual clue of what it looks like after the last report (but this is the same from report 1-6, except report 5, which is green)

abelb
#6 Posted : Monday, December 19, 2016 8:09:58 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/12/2014(UTC)
Posts: 155
Location: Netherlands

Thanks: 19 times
Was thanked: 11 time(s) in 11 post(s)
I will try to keep my project open and check how long it takes for the error to disappear (as it did last time), or whether it stays around this time. Either way, I have put this scenario in my DVCS, so if you need "eyes on the scene" I can do that for you.

And one more thing, which I didn't test before, I think, is to change the tests themselves. I just tried that, and the exception remains, and the path mentioned is also still the same.

Let me know if I can do anything more to help you analyze this one.

Maybe this helps: I just noticed that it seems like NCrunch is rerunning the successful test, but not the unsuccessful one (which is usually the other way around). This is true even when trying to rerun all of them at once. But now I clicked the offending test itself explicitly and asked it to be run again, and now it succeeds.

However, I am not sure whether this may have been caused by the sudden disappearance of the issue (like last time), or because of the visual clue that the test indeed was not run for one or another reason (and the BadImageFormatException report got stuck somehow).
abelb
#7 Posted : Monday, December 19, 2016 8:33:11 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/12/2014(UTC)
Posts: 155
Location: Netherlands

Thanks: 19 times
Was thanked: 11 time(s) in 11 post(s)
Oh darn, I think I have it.

The visual clue of what happens in the NCrunch test window is not what I expected. If I explicitly select that test to run in a new process, it succeeds (after first having the BadImageFormatException, then fixing the NCrunch configuration, then rerunning the test).

My setting is "run impacted tests". Which I take that, if the project's configuration changes, all that project's tests are impacted. I had the impression they were run again, since normally, otherwise, they have a question mark in front of them (or an ignore-label).

I also had the (false) understanding that when I hit "Reload and Rebuild component" that all tests would be rerun for that component. That is a false assumption.

If there is anything to learn from all this, it is that NCrunch essentially didn't do anything wrong, except if you would argue that it doesn't realize that if the NCrunch config changes, that this impacts the tests and that the tests should be run again. I may have made this assumption before. I would much rather see a question mark or suffer the impact from rerunning tests if I change the configuration.

I think NCrunch thinks that if the MSIL of the underlying test doesn't change, that the test is not impacted. But this is (I think somewhat obviously so) not true if metaparameters (references, x64 vs x86, debug vs release, environment variables) are changed.

NCrunch remains a great tool, but this time it got me fooled (and it is possible that I have been fooled by this before, as project-wide parameters are an important asset of my environment and may influence many tests, which I now think I may have thought of being successful when they weren't).

And as one more suggestion: I think it makes sense that if you encounter crashes / exceptions, that if you reload the component, reopen NCrunch, reopen Visual Studio that you run them again, as the environment has changed and the error may not make sense anymore.
abelb
#8 Posted : Monday, December 19, 2016 8:35:25 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/12/2014(UTC)
Posts: 155
Location: Netherlands

Thanks: 19 times
Was thanked: 11 time(s) in 11 post(s)
And it remains very surprising that: renaming the project from A ==> B will rerun the tests, and from B ==> A does not (or at least for some reason it shows the original error). As if it thinks "hey, these tests aren't impacted, I have an old cache of this project, let's show that".

All this together could be made to be my misunderstanding of how NCrunch does its work. But I'd like to take the opportunity to make again my request for a "Clean" button, just like Visual Studio has a "Clean solution" option. That way, I can be positive that nothing remains, that all tests become question-mark tests (not run) and that all builds and all tests *must* be run again to get a meaningful report.
abelb
#9 Posted : Monday, December 19, 2016 8:49:54 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/12/2014(UTC)
Posts: 155
Location: Netherlands

Thanks: 19 times
Was thanked: 11 time(s) in 11 post(s)
Sorry for the spam, but I think there is definitely a bug here. The closest I can get to "Clean" in NCrunch is the button "Resynchronise, Rebuild and Rerun all tests (Reset)". Doing that after first creating the faulty situation and then fixing it, will still show the BadImageFormatException.

Then, when I manually click the test and hit "Run selected test in new Taskrunner process", it succeeds.

So, the "rerun all tests" does not rerun all tests, at least not the way I'd expect it to.
Remco
#10 Posted : Monday, December 19, 2016 10:04:50 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 960 times
Was thanked: 1290 time(s) in 1196 post(s)
Ok, skimming over this, I think I've identified a couple issues that need to be looked at:

- Changing project settings doesn't affect test impact state when in some cases perhaps it should
- Renaming a project to a different name and back again doesn't consistently trigger test execution

I think that much of this comes from confusion over how the new impact detection system works. Previously, NCrunch has always been eager to run tests. Now under the new mode, it will only run them when an IL comparison shows that a change has happened. Because this works across sessions, simply reloading the component or the entire solution won't trigger the tests to be queued. For this reason, if you want a full 'clean', you'll not only need to reset the engine but also hit the 'Run all tests' button.

The real root of the issue here is the hole in the impact detection. Changing a project's CPU architecture doesn't affect the IL structure, so this doesn't trigger the impact detection, but it's clearly a very relevant change because code can break/unbreak depending on this setting.

I also wonder if there is a way to make these sorts of problems more obvious. Perhaps placing a timestamp at the top of the test output indicating when the test was last run?
abelb
#11 Posted : Monday, December 19, 2016 11:15:55 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/12/2014(UTC)
Posts: 155
Location: Netherlands

Thanks: 19 times
Was thanked: 11 time(s) in 11 post(s)
Thanks for your quick response.

Quote:
I also wonder if there is a way to make these sorts of problems more obvious. Perhaps placing a timestamp at the top of the test output indicating when the test was last run?

The primary focus of someone is usually at the icons, they are clearest: red means bad, green means good. My suggestion would be to do some or all of these:

  • Create a hover-help text on each text, this can contain info on the last test run datetime, last compile datetime and the like
  • Such balloontext can also indicate a warning, like "NCrunch detected that this test was not impacted by your latest change, click X to rerun"
  • An added benefit of balloons is that you can put more info in them, and accumulated text can be put in parent items, like "not all tests have been rerun since the last change"
  • But more than balloons, icons would be great. Change clear-red into troubled red and change clear green into troubled green to indicate that they are "stale", i.e. not run again
  • In addition to that, I certainly would welcome some more info in the logwindow of the NCrunch test screen, think about a caption bar with full path to the test method (before it's extended with testsource), the time it was build/run, repetition of success/fail icons. Or something like that. Just make it collapsible and people will be content with it.


For me, most help would be given from knowing that a test is "stale", or "out of sync" with its parent. Even if source doesn't change, I often find it hard to keep track. If I recompile a project, and rerun two or three individual tests, I can't see which one was newly run and which one is old (stale / out of sync / from before last build).

So, my vision ;) on this is that on each rebuild, no rerun tests keep the same icon, same color but a slightly troubled (darker / greyish) color.

Another thing you can do from within the NCrunch engine is to accept some exceptions as vital. That is, if an exception is vital, than any change may impact the whole project. Such exceptions are the ones that cannot be recovered from: BadImageFormatException (can be fixed by compile policy of file system rights change), OutOfMemoryException (can be fixed by environment change), StackOverflowException (can be fixed by debug into release change), but this can be a slippery slope: a SecurityException can mean you are not running in elevated mode, and a FileNotFoundException can be fixed by the environment.

Hmm, thinking out load: what if you recognize the exceptions that are not test exceptions (like NUnit / xUnit exceptions)? These are usually assertions anyway, but the rest often has to do with the environment.

Anyway, whatever you decide, improvements here are welcome. Still, making sure that Rerun All means exactly that, a Clean Everything is added and perhaps the greyish icons would already help many times over (and all have wider applicability than just this issue).
Remco
#12 Posted : Monday, December 19, 2016 11:22:48 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 960 times
Was thanked: 1290 time(s) in 1196 post(s)
abelb;9602 wrote:

So, my vision ;) on this is that on each rebuild, no rerun tests keep the same icon, same color but a slightly troubled (darker / greyish) color.


You may already be aware of this setting, but I thought I'd point it out just in case - http://www.ncrunch.net/documentation/reference_solution-configuration_only-consider-tests-outofdate-if-impacted. The impacted only engine mode overrides this and sets it to true.

Thanks for your ideas :)
abelb
#13 Posted : Monday, December 19, 2016 11:30:34 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/12/2014(UTC)
Posts: 155
Location: Netherlands

Thanks: 19 times
Was thanked: 11 time(s) in 11 post(s)
You're welcome, I updated while you were typing with more ideas ;).

Quote:
- http://www.ncrunch.net/d...-outofdate-if-impacted. The impacted only engine mode overrides this and sets it to true.

It looks like that was switched on by me, can't remember I did that. However, switching it off does not change the way out-of-date tests are shown after I rebuild it.
abelb
#14 Posted : Monday, December 19, 2016 11:34:11 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/12/2014(UTC)
Posts: 155
Location: Netherlands

Thanks: 19 times
Was thanked: 11 time(s) in 11 post(s)
Aha, it says "overridden by current engine mode". I have "Run impacted tests automatically". That looks like the engine mode this should actually have effect on, no? Or this setting simply means: run everything on each change. Which indeed is not useful for me, as my main project still has some 25000 tests or so.

So yeah, you are right, I did know about it, but thought it was something else.
Remco
#15 Posted : Tuesday, December 20, 2016 4:53:31 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 960 times
Was thanked: 1290 time(s) in 1196 post(s)
The 'Run impacted tests automatically, others manually' overrides this setting by setting it to True. It's default is False.

The setting controls the fading of the coverage markers and the presence of the question marks in the Tests Window. It's purely cosmetic - it doesn't change the actual behaviour of the engine. Based on what you've described, I think you probably want to turn it off for the 'Run impacted tests automatically' engine mode. You'll need to edit the engine mode itself to do that.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.132 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download