Friday, August 26, 2011

The type initializer for ... threw an exception

I was given some old code that I needed to port/partially rewrite.  The code had some funky things like a class trying to reference a static class as its base (which C# doesn't allow).  My guess is someone started to rewrite the code before they checked it into source control and never completed it.

Anyhow, I wrote a test app for this code after making a few tweaks and when this particular object was initialized it hit the declaration for the constructor and quit.  For some reason, .NET didn't throw any exceptions; it just stopped executing the code.

I wrapped my call with a try catch and caught the following: "The type initializer for 'NameOfClassICalled' threw an exception".  [This was a TypeInitializationException.]

After carefully stepping through the code I found my simple yet elusive mistake.  The code was initializing the base class which has static methods it was trying to load.  These static methods used the ConfigurationManager which uses the App.config... which I failed to include in my project.

Adding my app.config with the proper entries and I was off to the cases.  Reminder:  The parent assemblies config is the one that is used by assemblies called during execution.

Monday, August 22, 2011

Portable Storage Devices


Had a situation today where I needed to copy some files off a computer and didn't have a thumb drive handy.  Solution, I ended up using my cell phone which could have its SD card mounted as a hard drive.  This got me thinking and I put together a list of devices I could think of that can be used with your computer a hard drive aside from the typical.

1. Smart phones
2. MP3 players
3. Digital Camcorder
4. Digital Camera

Friday, August 19, 2011

SSL content

Ran into something the other day that I thought was worth mentioning.

If you have a site that is secured with SSL then pay close attention to where you are referencing graphics and other content from.  If you have a logo, for example, on an unsecured site that you reference then users will get a nasty message about the secured page having unsecured content.  This will happen each time the visit the site and possibly each page they visit.