configuration failed exception

Topics: Developer Forum
May 19, 2007 at 12:45 PM
I have customized RSBuild to run from my deployment project. It works alright when run as an executable. However when i refer to RSBuil.core from my program it fauls. Here is the detail

System.Configuration.ConfigurationErrorsException was unhandled
Message="Configuration system failed to initialize"
BareMessage="Configuration system failed to initialize"
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()
at System.Diagnostics.DiagnosticsConfiguration.Initialize()
at System.Diagnostics.DiagnosticsConfiguration.get_IndentSize()
at System.Diagnostics.TraceInternal.InitializeSettings()
at System.Diagnostics.TraceInternal.WriteLine(String message)
at System.Diagnostics.Debug.WriteLine(String message)
at RSBuild.Logger.LogMessage(String message) in D:\My Projects\Batch Controllers\SQLReportInstall\RSBuild.Core\Logger.cs:line 44
at RSBuild.Dispatcher.LogBanner() in D:\My Projects\Batch Controllers\SQLReportInstall\RSBuild.Core\Dispatcher.cs:line 61
at RSBuild.Dispatcher.Run() in D:\My Projects\Batch Controllers\SQLReportInstall\RSBuild.Core\Dispatcher.cs:line 29
at InVision2007.Setup.InstallInVision.CopyReports() in D:\My Projects\Batch Controllers\Setup\Setup\InstallInVision.cs:line 81
at InVision2007.Setup.InstallInVision.InstallInVision_Shown(Object sender, EventArgs e) in D:\My Projects\Batch Controllers\Setup\Setup\InstallInVision.cs:line 252
at System.Windows.Forms.Form.OnShown(EventArgs e)
at System.Windows.Forms.Form.CallShownEvent()
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at InVision2007.Setup.Program.Main() in D:\My Projects\Batch Controllers\Setup\Setup\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Dec 17, 2007 at 3:20 PM
Hi gancy,
It is not even working as executable for me. Please see my post and reply me. My name is muniappan
Feb 1, 2008 at 9:20 AM
I get the "Configuration system failed to initialize" exception too when RSBuild tries to validate the webservice.
It works fine for me when I run it through visual studio, but not when I run it as an exe.
If anyone has a suggestion please help, I'm desperate.
Feb 17, 2009 at 4:21 PM
OK, here's what I found and how I got it to work.  This may or may not work for you too.

The project worked fine within VS but would generate the "Configuration system failed to initialize" error when run anywhere else.  I found this blog,
which describes a problems with the format of the config file that will produce this error.  Sure enough, when you examine the formatting of the default RSBuild.config file you'll find that it does not follow the standard DotNetConfig.xsd schema defined for VS config files.  I'm assuming that the framework is looking for the standard formatting of the config file when it runs outside VS and when it doesn't find it, the error pops up.

Here's how I fixed it.
I copied the RSBuild.config file into the same directory and renamed it myRSBuild.config.  Then added this new file to the RSBuild project and set it's "Copy to Output Directory" property to"Copy Always" so that the new config file will be used in the build.  Then I set the Project Properites to use the new config file when doing a build-run in debug mode.  On the "Debug" tab of the "Properties" page, enter the name of the new config file as a command line arguement.  Now the project should build and run inside VS using the new config file.  Place all your config settings in this file instead of RSBuild.config.
Now after deploying you should be able to run the exe from the command line with the name of the config file as a command line parameter or you can create a simple batch file that will run the exe with the command line parameter.  These should run without producing the error.
Mar 2, 2009 at 12:31 AM
The problem is caused indeed if the RSBuild.config file resides in the same directory as RSBuild.exe. The .NET configuration system attempts to load it as a regular .NET configuration file, which it isn't, causing the exception described above.