Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Troubleshooting system.io.fileloadexception

Tags:

.net

I have a .net 3.5 WinForms application that runs fine on my machine, but on another machine it immediately crashes with a system.io.fileloadexception. Unfortunately, there are absolutely no details on which file failed to load, so I do not know where the problem actually is.

I believe I know which one it could be (SQL Server Compact edition), but before I aimlessly hunt, I wonder if there is a proper way to find out what caused the fileloadexception, other than using FileMon from SysInternals.

The only error message is:

EventType clr20r3, P1 myapplication.exe, P2 2.1.0.0, P3 490eca78, P4 myapplication, P5 2.1.0.0, P6 490eca78, P7 2e, P8 21, P9 system.io.fileloadexception, P10 NIL.

like image 749
Michael Stum Avatar asked Nov 17 '08 14:11

Michael Stum


3 Answers

Turn on fusion logging?

This blog entry from Brad Wilson gives information on what to do if that fails...

like image 169
Jon Skeet Avatar answered Oct 02 '22 12:10

Jon Skeet


You could try making your Main() method more robust to catch (and display) the exception... like so.

Frequently, the problem is that too much code gets into the outermost Main() method. JIT has to be able to fully understand Main(), otherwise none of your code can run. By making Main() simpler, you stand a chance. In the linked example, if MainCore() fails: fine, we can still catch the exception in Main().

This works because JIT is done on a method-by-method basis... i.e. MainCore() is not JITted until it is invoked, by which time we already have our try/catch in place.

like image 28
Marc Gravell Avatar answered Oct 02 '22 13:10

Marc Gravell


Hook and log AppDomain.AssemblyResolve

like image 25
Mark Brackett Avatar answered Oct 02 '22 13:10

Mark Brackett