Loading app.config from a remote location fails to load section handler.
-
Hi guys. We're trying to implement a centralized configuration for all .net applications and by so we have created a master configuration at a specific location. We're then creating a custom configuration manager that uses both the local app.config and the centralized master configuration. The master configuration is read using System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(string path, UserLevel level). The appSettings section and all other custom sections are read and available but our problem occurs when we try to read the sections from the master configuration using ConfigurationManager.GetSection(string sectionName). We get a TypeLoadException no matter what type of section handlers we use - .NET handlers or custom handlers, and the method returns a System.Configuration.DefaultSection object instead of the intended type. Could not load type 'System.Configuration.NameValueSectionHandler' from assembly 'System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Reading the same sections from the app.config of the exectuable produces no errors. Anybody with some ideas as to what causes the problem? -Larantz
for those about to code, we salute you
Please refer to the Forum Guidelines for appropriate posting. -
Hi guys. We're trying to implement a centralized configuration for all .net applications and by so we have created a master configuration at a specific location. We're then creating a custom configuration manager that uses both the local app.config and the centralized master configuration. The master configuration is read using System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(string path, UserLevel level). The appSettings section and all other custom sections are read and available but our problem occurs when we try to read the sections from the master configuration using ConfigurationManager.GetSection(string sectionName). We get a TypeLoadException no matter what type of section handlers we use - .NET handlers or custom handlers, and the method returns a System.Configuration.DefaultSection object instead of the intended type. Could not load type 'System.Configuration.NameValueSectionHandler' from assembly 'System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Reading the same sections from the app.config of the exectuable produces no errors. Anybody with some ideas as to what causes the problem? -Larantz
for those about to code, we salute you
Please refer to the Forum Guidelines for appropriate posting.The type System.Configuration.NameValueSectionHandler is in the System.Configuration namespace but it is actually defined in System.dll and not System.Configuration.dll as you might assume, so change your configuration section to <section name="" type="System.Configuration.NameValueSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> and it should work.
-
The type System.Configuration.NameValueSectionHandler is in the System.Configuration namespace but it is actually defined in System.dll and not System.Configuration.dll as you might assume, so change your configuration section to <section name="" type="System.Configuration.NameValueSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> and it should work.
I'll try that. Thanks for the tip. :) -Larantz
for those about to code, we salute you
Please refer to the Forum Guidelines for appropriate posting. -
The type System.Configuration.NameValueSectionHandler is in the System.Configuration namespace but it is actually defined in System.dll and not System.Configuration.dll as you might assume, so change your configuration section to <section name="" type="System.Configuration.NameValueSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> and it should work.
It seems that the section handler did load so the TypeLoadException is gone. But instead of actually returning a NameValueCollection - it still just returns a System.Configuration.DefaultSection which is useless. I just can't get my head around why this is occurring. It's the same for custom section handlers. -Larantz
for those about to code, we salute you
Please refer to the Forum Guidelines for appropriate posting. -
It seems that the section handler did load so the TypeLoadException is gone. But instead of actually returning a NameValueCollection - it still just returns a System.Configuration.DefaultSection which is useless. I just can't get my head around why this is occurring. It's the same for custom section handlers. -Larantz
for those about to code, we salute you
Please refer to the Forum Guidelines for appropriate posting. -
You might find this useful http://www.eggheadcafe.com/software/aspnet/30832856/backwards-compatibility-o.aspx[^]
Well that sure answers it. I'll have a look at the document mentioned there. Thanks mate! -Larantz
for those about to code, we salute you
Please refer to the Forum Guidelines for appropriate posting.