views:

55

answers:

1

I tried making a custom configuration class that went on like this:

WatcherServiceInfoSection<TWatcherServiceDetailElement>

where TWatcherServiceDetailElement is a ConfigurationElement inside it.

Now when I call the type in the ConfigSections area of AppConfig I get the error:

An error occurred creating the configuration section handler for WatcherServiceInfo: 
Could not load type 'Library.Common.Utilities.ConfigurationHandler.WatcherServiceInfoSection<ASNDPService.Configuration.WatcherServiceDetailElement>' from assembly

Is what I'm doing possible? Can I have generic types in the type attribute for a custom section element?

EDIT

Additionally, how about ConfigurationElementCollection objects? Like in the above example, how could I do a

[ConfigurationProperty("WatcherServiceDetails", IsRequired = true, 
IsDefaultCollection = true)]
[ConfigurationCollection(typeof(TWatcherServiceDetailElement), AddItemName = "WatcherServiceDetail")]
public WatcherServiceDetailCollection<TWatcherServiceDetailElement> WatcherServiceDetails

I'm aware that type parameters aren't allowed for attributes and that's what I want to know how to do.

+1  A: 

you need to specify the full name of the type.

This includes the full name of the generic type followed by a ` and the number of generic type parameters with the full names of the type parameters in [...]

e.g.

<component id="FooRetriever"
           service="Namespace.IRetrievable`2[[Namespace.Foo, Assembly],[System.String]], Assembly"
           type="Namespace.FooRetriever, Assembly"/>

I will try to whip up a more reasonable example.

see http://theburningmonk.com/2010/03/castle-windsor-tips-specifying-generic-types-in-config-file/

also see http://stackoverflow.com/questions/454726/including-a-generic-class-in-unity-app-config-file

Sky Sanders