tag:blogger.com,1999:blog-8263949408347549596.post8141340123323035170..comments2023-10-23T23:19:01.111+02:00Comments on Object-Oriented Software Development: Custom ConfigurationManager providerWiktor Zychlahttp://www.blogger.com/profile/04420514974154487039noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-8263949408347549596.post-32227035638784682932013-06-06T10:27:48.765+02:002013-06-06T10:27:48.765+02:00Problem solved.
In class DynamicConfigSystem repla...Problem solved.<br />In class DynamicConfigSystem replace<br /><br /><b>private ConnectionStringSettingsCollection connectionStrings;</b><br />with<br /><b>private ConnectionStringsSection connectionStrings;</b><br /><br />and<br /><br /><b>this.connectionStrings = <br /> ConnectionStrings != null ? <br /> ConnectionStrings : new ConnectionStringSettingsCollection();</b><br />with<br /><b>this.connectionStrings = <br /> ConnectionStrings != null ? <br /> ConnectionStrings : new ConnectionStringsSection();</b>Anonymoushttps://www.blogger.com/profile/08102871309487413257noreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-28646056962055816582013-06-04T15:07:42.892+02:002013-06-04T15:07:42.892+02:00Thanks: after adding your code I can successfully ...Thanks: after adding your code I can successfully inject my custom provider in ASP NET context.<br />Now ConfigurationManager.AppSettings() property and ConfigurationManager.GetSection() method provide information from my custom provider.<br />When I try to access ConfigurationManager.ConnectionStrings() property, a ConfigurationErrorsException is raised ("The configuration section 'connectionStrings' has an unexpected declaration").Anonymoushttps://www.blogger.com/profile/08102871309487413257noreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-30603944019533560732013-06-03T09:39:46.148+02:002013-06-03T09:39:46.148+02:00@Umberto: add a line before the actual configurati...@Umberto: add a line before the actual configuration is set: configurationManagerType.InvokeMember( "s_initState", System.Reflection.BindingFlags.SetField | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic, null, configurationManagerType, new object[] { 0 } ); <br /><br />This changes the internal state to "not initialized" thus allowing you to replace any existing configuration subsystem with your own.Wiktor Zychlahttps://www.blogger.com/profile/04420514974154487039noreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-83529780837091090542013-05-31T12:52:58.469+02:002013-05-31T12:52:58.469+02:00Nice trick.
Unfortunately I could not make it work...Nice trick.<br />Unfortunately I could not make it work within ASP NET context.<br />If SetConfigurationSystem method is used anywhere in the page life cycle, an error is raised ("The configuration system has already been initialized").<br />Maybe the ConfigurationManager object is initialized by ASP NET worker process before any application request and this prevents the custom provider injection :(Anonymoushttps://www.blogger.com/profile/08102871309487413257noreply@blogger.com