Wednesday, December 1, 2010

.Net 3.5 WCF Application + .Net 4.0 Conversion = Missing Config Sections?

As we convert .Net 3.5 projects to .Net 4.0, I had a couple really mysterious issues where WCF Windows Services or command line (console) applications quit working on some servers, and only some environments. Eventually they would get fixed but I hadn't been able to pin down why they quit working in the first place, or what I did to fix them. 

Example: we use MSEntLib logging in this particular WCF Windows Service. The project was converted to .Net 4.0, committed to source control, the continuous integration build server detected the changes, built the project and deployed it to the first test environment. Here's the error it would throw when the build server's deployment routine started the windows service after deployment:

Service cannot be started. System.Configuration.ConfigurationErrorsException: The configuration section for Logging cannot be found in the configuration source.
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp[T](IReadWriteLocator locator, ILifetimeContainer lifetimeContainer, IConfigurationSource configurationSource)
   at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.get_Writer()
   at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(Object message, ICollection`1 categories, Int32 priority, Int32 eventId, TraceEventType severity, String title, IDictionary`2 properties)
   at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(Object message)
   at <snip> - that's enough, you get the picture. 

I looked at the config (“{AppName}.config”), and the logging section was in there. Restart the service, same error. Look for XML errors in the config, find none, mess with it a little, start the service, same error. Rinse and repeat until you've torn it apart so much that when you put it back together it works and you're like "Whuck?" and then you start drinking on the job :(

I finally figured it out - I'm not 100% sure this is accurate, but the best I can figure out is pre-.Net 4.0 - say 2.0-3.5 - on a WCF Windows Service at least and probably for all .net command line (console) applications you could get away with the config file being “{AppName}.config” even though the book says “{AppName}.exe.config”. When we straight converted to .Net 4.0 the non-exe variant became illegal, you have to use  “{AppName}.exe.config” or it won't go. 

-Kelly Schoenhofen

No comments:

Post a Comment