G
Guest
I'm implementing a IConfigurationSectionHandler using generics, and the
ConfigurationManager is failing to create the type. It appears the
ConfigurationManager isn't using the specified assembly to find the type for
the generic. (Sound confusing? Here's a sample):
namespace TestApp
{
public class TestClass<T> : IConfigurationSectionHandler
{
public object Create(object parent, object configContext, XmlNode
section)
{
System.Diagnostics.Debug.WriteLine("It works, we were created!");
return null;
}
}
}
Here's my app config snippet:
<configSections>
<section name="test" type="TestApp.TestClass`1[TestApp.SomeClass],
TestApp" />
</configSections>
<test>
</test>
Here's the class I'm trying to use with my generic ConfigSectionHandler:
namespace TestApp
{
public class SomeClass
{
public SomeClass()
{
}
}
}
Here's the snippet where I try to use the config section handler:
object o = ConfigurationManager.GetSection("test");
This throws a ConfigurationErrorsException:
Could not load type "TestApp.SomeClass" from assembly 'System.Configuration,
Version...
If you replace TestApp.SomeClass in the app.config above with System.Int32
it works.
I can create this type no problem using Activator.CreateInstance, so I'm
convinced it's a problem in the COnfigurationManager's instantiation code.
Any help is appreciated.
Todd Berry
Note: This is using 2005 RC1 (.NET 2.0); you must add
System.Configuration.dll to project to reproduce this.
ConfigurationManager is failing to create the type. It appears the
ConfigurationManager isn't using the specified assembly to find the type for
the generic. (Sound confusing? Here's a sample):
namespace TestApp
{
public class TestClass<T> : IConfigurationSectionHandler
{
public object Create(object parent, object configContext, XmlNode
section)
{
System.Diagnostics.Debug.WriteLine("It works, we were created!");
return null;
}
}
}
Here's my app config snippet:
<configSections>
<section name="test" type="TestApp.TestClass`1[TestApp.SomeClass],
TestApp" />
</configSections>
<test>
</test>
Here's the class I'm trying to use with my generic ConfigSectionHandler:
namespace TestApp
{
public class SomeClass
{
public SomeClass()
{
}
}
}
Here's the snippet where I try to use the config section handler:
object o = ConfigurationManager.GetSection("test");
This throws a ConfigurationErrorsException:
Could not load type "TestApp.SomeClass" from assembly 'System.Configuration,
Version...
If you replace TestApp.SomeClass in the app.config above with System.Int32
it works.
I can create this type no problem using Activator.CreateInstance, so I'm
convinced it's a problem in the COnfigurationManager's instantiation code.
Any help is appreciated.
Todd Berry
Note: This is using 2005 RC1 (.NET 2.0); you must add
System.Configuration.dll to project to reproduce this.