deserialize to C# class from external config file?

G

Guest

I'm using System.Configuration in .NET 2.0 to load in values
from an externally specified config file and deserialize
them into a C# class. During deserialization, I'm getting
an exception thrown by .NET It's having a problem with
the <connections> element seen below. I've tried different things, but
still I can't get the deserialize to succeed. Here's the problem in
detail below.

Can anybody tell me what I'm doing wrong? Shouldn't
[xmlArray] work?

Thx,
Tom

The app.config file looks like this:

<configuation>
<configSections>
<section name="dataAccessSection"
type="Framework.Data.DataAccessConfig,Framework.Data,Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null"/>
</configSections>

<dataAccessSection configSource="DataAccess.config"/>
</configuation>

DataAccess.config looks like this:

<dataAccessSection>
<connections>
<connection name="fsa">
<connectionEnvs>
<connectionEnv envName="INT1" assembly="System.Data,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
type="System.Data.OleDb.OleDbConnection"
connectionString="Provider=OraOLEDB.Oracle;Password={0};Persist Security
Info=True;User ID=fiisbsvc;Data Source=dbenv022"
connectionStringPassword="lttC8Hg29Nfks+3QPI8Hxg==">
</connectionEnv>
</connectionEnvs>
</connection>
</connections>
<commands/>
<maps/>
</dataAccessSection>


The C# class looks like this:

using System;
using System.Xml.Serialization;
using System.Configuration;

namespace Framework.Data
{
/// <summary>
/// Represents the root of all data access configuration information.
/// </summary>
public class DataAccessConfig : ConfigurationSection
{
#region Constructor(s)

/// <summary>
/// Initializes a new instance of the <see cref="DataAccessConfig"/>
class.
/// </summary>
public DataAccessConfig()
{
_sectionName = _defaultSectionName;
}

#endregion

#region Config Manager
private const string _defaultSectionName = "dataAccessSection";
private string _sectionName;

#region Connection Config

private ConnectionConfigCollection _connections = new
ConnectionConfigCollection();

/// <summary>
/// Gets or sets the collection of connection configuration items
associated with this application.
/// </summary>
/// <value>The collection of connection configuration items associated
with this application.</value>
[XmlArray("connections")]
[XmlArrayItem("connection")]
// [ConfigurationProperty("connections")]
// [ConfigurationCollection(typeof(ConnectionConfigCollection))]
public ConnectionConfigCollection Connections
{
get
{
return _connections;
}
set
{
_connections = value;
}
}
..
..
..
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top