I was attempting to do rebuild of a WPF client application I’m building, and started getting this all of a sudden:

A System.TypeInitializationException error occured at System.ServiceModel:
The type initializer for 'System.ServiceModel.ClientBase`1' threw an exception.

I have a client class that I use to put all of my service calls in.  This class inherits from System.ServiceModel.ClientBase.  It was the instantiation of this class which was throwing the exception.

Turns out I had changed the App.config to add some WCF logging in there, and had forgotten to enclose the bit in a <system.diagnostics> tag.  Oops.  Anyway, I’ve seen this before - configuration errors will throw type initializer exceptions in classes that inherit from ClientBase and ServiceHost.  Fixing the error in my App.config fixed the exception.

Teaches me to go longer than an hour without making a build!



One Comment to “System.ServiceModel Type Initialization Exception”

  1. Rob Fearn | August 18th, 2009 at 9:28 pm

    Thanks so much for this info, saved me hours of phaffing about :-)

Leave a Comment

Spam Protection by WP-SpamFree