Monday 6 January 2014

TILog.exe crashes with System.BadImageFormatException, after a unit test started

When performing unit tests from Visual Studio 2010, I got this strange error.


What is TILOG.EXE?

This is "Microsoft Visual Studio Logger". It seems that this utility is called by Visual Studio and acts as a logger for the tests. I got this help message from another machine.


What was the actual error?


"Unhandled Exception: System.BadImageFormatException: Could not load file or assembly 'TiLog.exe' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded."

Does it sound reasonable? Maybe not, but it turned out that it didn't lie. See the next section.

How to fix the problem
  1. Open up C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\DataCollectors\TILog.exe.config using your favourite editor. It should be something like this: 
    • <?xml version="1.0" encoding="utf-8" ?>
    • <configuration>
    •   <startup>
    •     <supportedRuntime version="v4.0.40219" />
    •     <supportedRuntime version="v2.0.50727" />
    •   </startup>
    •   <runtime>
    •     <generatePublisherEvidence enabled="false"/>
    •   </runtime>
    • </configuration>
    • See the version there - v4.0.40219. Is it correct? Probably not. I checked my system to see if my machine has .Net 4.0.40219 and the version it had was 4.0.30319. Actually, it seemed that the number "40219" was from the TILOG.exe itself! See the 2nd screenshot above - the version was 10.0.40219.1. 
  2. So I added a new line to have a correct version on it. 
    •     <supportedRuntime version="v4.0.40219" />
    •     <supportedRuntime version="v4.0.30319" />
    •     <supportedRuntime version="v2.0.50727" />
    • It's up to you to completely remove the first line or keep it. 
  3. Run TiLog.exe from command prompt or restart your unit test. 
Sent from Evernote