What specifically causes the exception with the message "Bad IL range"?
I've gotten an error report from a customer of mine with this message, but I can't see the exception type. Googling on this text yields very different results, and I suspect this is something pretty low level in .NET/C#, which can occur in many different situations. I assume IL is "Intermediate Language" in this context.
So what exactly causes this exception, and what may the common underlying reasons for it to happen be?
Exception type is BadImageFormatException
, it's thrown when an assembly is corrupted (complete exception message should explain which assembly). There could be many and various reasons for this to happen: viruses, hardware failure, software bugs or a wrong action taken by the user. The exception message and the Fusion log property will contain more information about what kind of error it represents.
You can't do much about that, if the problem persists probably he needs to reinstall your application or .NET Framework, if it did happen just once then he should check for viruses or do a serious hardware test.
The runtime verifies loaded assemblies and specifically - checks the validity of the supplied CIL - it detects variety of different problems in the CIL structure and the CIL stream.
Although I've never seen this specific problem by myself, I guess the most common reason for this would be the physical corruption of one of application or .NET assemblies.
I would try to reinstall your application (and/or the .NET runtime).
My issue was a dodgy working directory. So a bad DLL somewhere in that, perhaps a nuget reference. Updating all my nuget packages didn't work, solution rebuild didn't work, a pc restart didn't work.
Doing a fresh checkout from my source control (svn) into a new working directory resolved the issue.
I'm on Win10, so there might be something deeper here but I haven't had any further issues for a few days since.
In my case this error occurred because of disposing an assembly object in event of _FormClosing, like bellow:
if (_kishpos != null)
_kishpos.Dispose();
no need to dispose assembly object's in _FormClosing() event.
comment or remove it, to fix your "Bad IL range" error.
//if (_kishpos != null)
// _kishpos.Dispose();
my error fixed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With