Configuration system failed to initialize

by data-centric on November 13, 2010

I recently needed to change the root namespaces on a solution, I know this something that I should have perhaps thought out in more detail before getting so far in to the project but that’s not the point of this post. I stand to be corrected, but there doesn’t seem to be a way of doing this easily in VS2008 without manually changing all classes. I don’t have ReSharper but do have a great little tool called WildEdit which I used to do a search and replace through every file in the solution. WildEdit also makes backups of all files so it easy to reverse out of something so drastic if required. After renaming my namespaces, the solution would build OK but wouldn’t run and NUnit fell over when trying to test it too.

When this actually happened I was getting “Configuration system failed to initialize” errors, however when I tried to re-create the problem several weeks later for this blog, the solution wouldn’t build at all I was getting a completely different error:

“Error while trying to run project: Could not load file or assembly … or one of its dependencies. The module was expected to contain an assembly manifest”

The message in the Error List in Visual Studio wasn’t much help either:

Unexpected error creating debug information file

So in either case, the error information was of limited use and googling yielded no obvious help either. I suppose there aren’t that many people who are either stupid enough to need to change name spaces in the first place, or who use quite such a “sledge hammer to crack a nut” approach. But, in my hunt for a solution I did come across some references to app.config data being cached and when this problem originally occurred there was some evidence to indicate a problem with the config file.

On Vista, this could be in one or both of the following paths:

C:\Users\User Name\AppData\Local\company_name
C:\Users\ User Name \AppData\Roaming\company_name

In one of these folders, I found the following:

Cached app.config folders

On a hunch, I deleted both folders and tried to rebuild the solution and re-run my unit tests. Surprise, surprise! Everything now worked OK. Unfortunately, time pressures at the time meant I couldn’t investigate further since the problem was now fixed and I needed to crack on. I don’t profess to be as deeply familiar with .NET as I am with SQL Server so if anyone can shed any light on this, please feel free to add a comment.

So the moral of the story is either to plan your namespaces properly in the first place (my preferred option) or to find a more subtle way of changing namespaces that actually works.

Previous post:

Next post: