The type name or alias EnumTypeConverter[MaxMind.Db.FileAccessMode] could not be resolved.

Jan 4, 2015 at 3:25 PM
I'm trying to configure Unity to inject the MindMax DatabaseReader class:

http://maxmind.github.io/GeoIP2-dotnet/

The constructor of this class has several forms, but the one I'm wanting to use is:
public DatabaseReader(string file, FileAccessMode mode = FileAccessMode.MemoryMapped);
At first, I just tried passing the the file argument, but that didn't work. Unity complained that the there was no constructor with a single file parameter, dispite the second parameter being optional. So I tried to pass both and ran into problems with the Enum parameter.

I found the post in this forum about creating a type converter. Luckily it was an EnumTypeConverter and looked like I can use as-is. However, unity cannot seem to "find" either the type converter class.

Here's the type converter I am using:
namespace MySite.Web
{
    using System;
    using System.ComponentModel;
    using System.Globalization;


    public class EnumTypeConverter<T> : TypeConverter
    {
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            return sourceType.GetType() == typeof(string);
        }

        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        {
            return typeof(T).IsEnum;
        }

        public override object ConvertFrom(
            ITypeDescriptorContext context,
            CultureInfo culture,
            object value)
        {
            return Enum.Parse(typeof(T), (string)value);
        }

        public override object ConvertTo(
            ITypeDescriptorContext context,
            CultureInfo culture,
            object value,
            Type destinationType)
        {
            return Enum.GetName(typeof(T), value);
        }
    }
} 
Here's the relevant unity config sections:
  <alias alias="DatabaseReader" type="MaxMind.GeoIP2.DatabaseReader, MaxMind.GeoIP2" />

  <alias alias="EnumTypeConverter" type="MySite.Web.EnumTypeConverter, MySite.Web" />

      <register type="DatabaseReader" mapTo="DatabaseReader">
        <lifetime type="Singleton" />
        <constructor>
          <param name="file">
            <value value="~/App_Data/GeoLite2-City.mmdb" />
          </param>
          <!--<param name="mode" parameterType="MaxMind.Db.FileAccessMode, MaxMind.Db">-->
          <param name="mode">
            <value value="MemoryMapped" typeConverter="EnumTypeConverter[MaxMind.Db.FileAccessMode]" />
          </param>
        </constructor>
      </register>
The error message is:
The type name or alias EnumTypeConverter[MaxMind.Db.FileAccessMode] could not be resolved.
I am using Unity 2.