Tuesday, January 30, 2007

The type initializer for * threw an exception

The type initializer for *insert your favorite class here* threw an exception

This was driving me crazy, there's not a whole lot of info out there about this error, I should've used my psychic debugging powers (yes, I have those too =op) before

my scenario is a web service (.net 2.0) calling (deep down) into some code that does reflection to instantiate some classes, the exact same code works just fine under a web application, that's what's bizarre, how's a web service different to a web app on regards to permissions and security?

anyway, almost from the beginning I suspected it had to do with permissions, but being a web service, and the same code running fine under the web app made me leave that as a last option, so I looked and didn't find any real answer, then decided to configure a different user (with more permissions than the default asp_net) in IIS to run my web service, it ran just fine after that

ok, now I know the problem is permissions but I'm not happy with the "fix", so I'll keep looking and trying for a more elegant solution

free tip for those of you who may not know this one
enter "The type initializer for * threw an exception" in google... it's a beautiful thing, Google takes wild cards as part of a search, it works with multiple wild cards in one phrase too

No comments: