This error cost me far too much time the other night whilst I was trying to migrate an application from preproduction (where it worked fine) to production (where it shit itself and gave that error when I tried to start it up.) It was a windows service that used a regular config file for its config information, and I added a Web Services Extensions section to that config file in order to raise the size limit allowed for file transfers. (I know Microsoft claim its a security mechanism, but for us its just been a constant pain in the ass.)
There are lots of articles around that say what can cause this, but none which address the actual cause in my case. This should have been caught at a preproduction level and I can only guess that security on my preprod box must be lacking somewhat – a lower restriction level then our production box perhaps.
In your config file, you’ll have something like this:-
You need that section to allow you to include the microsoft web config section later in the pile, and its in this section that my error lay. I copied it verbatim from somewhere on the web when I was first troubleshooting the size limit problem (I wasn’t sure you could use this seciton in an app config, most wse apps discussed seem to be web apps, not windows services, funnily enough.).
My first thought when I identified this as a potential problem area was that I’d forgotten to replace the publickeytoken with the actual one my copy of the dll uses. No love there though, they were the same value 😉
I left it then and didn’t come back to it till i’d wasted plenty of time chasing other blind holes to notice the version number.
The one i’d copy, as you can see there, states the file is version 184.108.40.206. Turns out my copy of the dll that I was using with the app was version 220.127.116.11. I only found that out by accident, looking at the dll in the file viewer of visual studio.
I guess the moral of this story is to check the file information first and ensure its all ok, before chasing obscure host-file bugs and other weird things the net was suggesting.