locked
Bug Report/Solution: app.config: Configuration system failed to initialize RRS feed

  • General discussion

  • Issue:  When I try to run my application I get an error message like this....

     

    An unhandled exception of type 'System.InvalidOperationException' occurred in <your app>.exe

    Additional information: An error occurred creating the form. See Exception.InnerException for details.  The error is: Configuration system failed to initialize

    ... that occurs suddenly after other succesful runs -- but some changes were made since the last run.

     

    Complications:  The natural step to take is to open the app.config file and see what's not being configured.  In my case I had about seven My.Settings values entered through the Project Properties Settings tab.  These settings were mostly used for binding control properties to, including backcolor and forecolor.  When I opened up the config file nothing seems to be wrong (in fact no build errors were reported).  However, if I scroll over to the far upper right of the file I come across the requiredPermission attribute setting that is created by Visual Studio.  It suddenly creates a warning that says this...

     

    The 'requirePermission' attribute is not declared.

    I had encountered this once before and went through extrordinary lengths to resolve it even though it has no discernable impact on the application itself.  The solution I tried before was one proposed by someone else, described in this post...

    http://www.peterritchie.com/Hamlet/Downloads/74.aspx

     

    ...where someone rewrote the DotNetConfig.xsd schema file that defines what the elements mean when the app.config file is being read.  This is of course a very risky thing to do, messing with this file, but ultimately it had no lasting effect so i do not recommend doing this... and besides it is a red herring for this bug.

     

    In addition to the above warning there were other information-level citations issued by VS that indicated it could not recognize most of the XML elements associated with the user-defined settings.  Here's a few...

     

    Could not find schema information for the attribute 'serializeAs'. 

    Could not find schema information for the element 'applicationSettings'.

    Could not find schema information for the element 'value'.

    Could not find schema information for the element 'setting'.
    Could not find schema information for the element 'name'.

    ... pretty much it had a form of dementia like dear old grandpa.

     

    Solution:  I knew that I had been messing with binding the form's controls to these settings so instead of wiping them out like they were corrupted or something of the like I decided to just change the scope setting from Application to User.  This immediately cleared up the problem and everything ran correctly again.  The Warning and Information citations will go away if you close the app.config file or at most close VS and reopen the project/solution.

     

    So the issue it turns out was that somehow one of my forms was trying to change a setting that is read only by definition (as Application scope) even though there is no code doing this.  I'm not sure really how it started since I just set the form backcolor and that was all. 

     

    In fact, if I remove the setting and add a new one afterwards that is Application Scope I get the same error -- even if I do not bind anything to it.  So obviously this is a bug deep in Visual Studio.

     

    Anyhow, I hope this helps someone out!

     

    Friday, March 28, 2008 7:56 PM