All,
I am still getting the following error - 'Object reference not set to an
instance of an object' below is the code I am using.
I have the following App.Config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="MyCompany">
<section name="Filelist"
type="ConfigurationSample.SampleConfigurationHandler,MyAssembleyName" />
</sectionGroup>
</configSections>
<MyCompany>
<Filelist location="C:\Program Files\zzz\xxx.EXE">
<Files>
<add type=".jpg" hex="FFD8FFE0" />
<add type=".gif" hex="47494638" />
<add type=".bmp" hex="424D" />
</Files>
</Filelist>
</MyCompany>
</configuration>
I have one assembley (MyAssembleyName.dll) that contains the following code
to get the section I need:
using System;
using System.Configuration;
using System.Xml;
namespace ConfigurationSample {
public class SampleConfiguration
{
#region fields and properties
private string m_Exe;
public string ExeName
{
get { return m_Exe; }
set { m_Exe = value; }
}
#endregion
#region Constructors
public SampleConfiguration() {}
#endregion
public static SampleConfiguration GetConfig{
get {return
(SampleConfiguration)ConfigurationSettings.GetConfig("MyCompany/Filelist");}
}
internal void LoadValues(XmlNode node) {
XmlAttributeCollection attributeCollection = node.Attributes;
m_Exe = attributeCollection["location"].Value;
}
}
public class SampleConfigurationHandler : IConfigurationSectionHandler
{
public object Create(object parent, object context, XmlNode node)
{
SampleConfiguration config = new SampleConfiguration();
config.LoadValues(node);
return config;
}
}
}
In a separate solutuion I have a webform that has a reference to
MyAssembleyName.dll and I call the following method on the page load:
using ...
using ConfigurationSample;
try
{
string exeName = SampleConfiguration.GetConfig.ExeName
}
catch (Exception ex)
{
throw ex;
}
An exception is thrown saying - 'Object reference not set to an instance of
an object' what am I doing wrong?
Thanks
Msuk
"Richard Grimes [MVP]" wrote:
> msuk wrote:
> > The GetConfig() is a static method called as follows from my aspx form
> >
> > string exe =
> > ConfigurationSample2.SampleConfiguration.GetConfig.ExeName - fails
> > with 'Object reference not set to an instance of an object' what am I
> > doing wrong.
>
> Huh?
>
> You should do this:
>
> string exe =
> System.Configuration.ConfigurationSettings.GetConfig("filelist");
>
> Richard
> --
> www.richardgrimes.com
> my email (E-Mail Removed) is encrypted with ROT13 (www.rot13.org)
>
>
>