"sqlServerCatalogNameOverwrites" is using obsolete type?

Posts   
 
    
clint
User
Posts: 150
Joined: 15-Nov-2005
# Posted on: 15-Nov-2010 16:47:00   

Using LLBLGen 2.6 Final Version Using Adapter template

We need to make a setup program for our application that alters the configuration file. Since some of the items in the configuration file are customer-specific, we are trying to save those sections from the original configuration file and copy them into the new configuration file that we are installing. One of those customer-specific sections is the LLBLGen section: sqlServerCatalogNameOverwrites.

"sqlServerCatalogNameOverwrites" uses type of "NameValueSectionHandler":


<section name="sqlServerCatalogNameOverwrites" type="System.Configuration.NameValueSectionHandler"/>

NameValueSectionHandler appears to be a .NET 1.x type that can't be used with ConfigurationManager.GetSection(). You get a compilation error if you try to cast the GetSection() result to "NameValueSectionHandler".


NameValueSectionHandler catalogNameOverwritesSection = (NameValueSectionHandler)webConfig.GetSection("sqlServerCatalogNameOverwrites") as NameValueSectionHandler;

If you don't cast the result of GetSection:


ConfigurationSection catalogNameOverwritesSection = webConfig.GetSection("sqlServerCatalogNameOverwrites");

the debugger will say the result is of type "DefaultSection".

I can cast the result to "DefaultSection and eventually extract the raw XML code, but what I really wanted was a collection of Key/Value pairs since that is more user-friendly to work with.


DefaultSection catalogNameOverwritesSection = (DefaultSection)webConfig.GetSection("sqlServerCatalogNameOverwrites");
ElementInformation element = catalogNameOverwritesSection.ElementInformation;
SectionInformation sectionInfo = catalogNameOverwritesSection.SectionInformation;
string xml = sectionInfo.GetRawXml();

I'm curious, is there another type we can use for "sqlServerCatalogNameOverwrites" that derives from type "ConfigurationSection"? Has this been changed in later versions of LLBLGen?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 16-Nov-2010 02:01:53   

Use this (without "as"):

NameValueCollection xyz = (NameValueCollection)ConfigurationSettings.GetConfig("Xyz");

If you receive exception, please post the complete stack trace and error message. What .Net framework version are you using?

btw, NameValueCollection is not obsolete, it's suported in 4, 3.5, 3.0, 2.0, 1.1, 1.0 (http://msdn.microsoft.com/en-us/library/system.collections.specialized.namevaluecollection.aspx )

David Elizondo | LLBLGen Support Team
clint
User
Posts: 150
Joined: 15-Nov-2005
# Posted on: 16-Nov-2010 17:14:22   

daelmo wrote:

Use this (without "as"):

NameValueCollection xyz = (NameValueCollection)ConfigurationSettings.GetConfig("Xyz");

If you receive exception, please post the complete stack trace and error message. What .Net framework version are you using?

btw, NameValueCollection is not obsolete, it's suported in 4, 3.5, 3.0, 2.0, 1.1, 1.0 (http://msdn.microsoft.com/en-us/library/system.collections.specialized.namevaluecollection.aspx )

Thanks for the reply.

True, NameValueCollection isn't obsolete but the method for getting it, ConfigurationSettings.GetConfig(), is obsolete. http://msdn.microsoft.com/en-us/library/system.configuration.configurationsettings.getconfig.aspx

ConfigurationSettings.GetConfig() still works, but it appears that Microsoft would rather not have programmers use it for new code. That is why I was curious if LLBLGen had changed sqlServerCatalogNameOverwrites to a type that can be used by ConfigurationManager.GetSection(). If it had been, I would've used it. But since it hasn't then I will use ConfigurationSettings.GetConfig().

Thanks.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 16-Nov-2010 22:02:39   

ConfigurationManager.GetSection() returns a ConfigurationSection object, which although not a name/value list does have a .Item property which can be indexed by name.

Matt

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39898
Joined: 17-Aug-2003
# Posted on: 17-Nov-2010 11:09:18   

We build the runtime against .net 2, and it's not deprecated in .net 2. It might have been made obsolete in 3.5 or 4, not sure, the msdn docs show it's been deprecated even in the .net 2 which is nonsense, as it would have given a warning during build, which it doesn't.

It's indeed wiser to use the different types instead in newer code, but as long as we don't get a warning during builds, we leave the type in / code in as-is, as it works properly.

Frans Bouma | Lead developer LLBLGen Pro
clint
User
Posts: 150
Joined: 15-Nov-2005
# Posted on: 18-Nov-2010 15:51:13   

MTrinder wrote:

ConfigurationManager.GetSection() returns a ConfigurationSection object, which although not a name/value list does have a .Item property which can be indexed by name.

Matt

I never tried that. Thanks!