Thursday, July 3, 2014

The type initializer '' threw an exception.

Mainly this error occurs when it fails to load a dependent dll/assembly. It couldn't find the dependency, or the version number was different.

This error mostly occurs when you deploy your application to production server. It might work fine in development machine. Things to make sure in this case:

All your dependencies are deployed properly.
Check the version numbers for the dependencies.

I had this issue when my multiple projects where using a logging dll. It worked fine in dev machine, but when deployed to the test server, booommmm..... ended up with this error.

So I made sure that all the projects in my solution are referring to the logging dll from same common location (may be a folder in the solution/GAC to hold common shared assemblies), with same version number. After making these changes and making sure all other dll's are deployed correctly, it worked like a charm.

Hope this tip helps somebody...... njoy..