title: Unable to create Generic CustomAttributeData properly when using programatically generated Enum
body: <p>I am trying to source a PropertyGrid with a dynamically generated object.</p>
  
  <p>For combo selections on this property grid, I have built a TypeConverter (where T is an enum, defining the list of options):</p>
  
  <pre><code>    public class TypedConverter&lt;T&gt; : StringConverter where T : struct, IConvertible
      {
          ...
  
          public override System.ComponentModel.TypeConverter.StandardValuesCollection
              GetStandardValues(ITypeDescriptorContext context)
          {
              if (!typeof(T).IsEnum) throw new ArgumentException("T must be an enumerated type");            
  
              string[] values = Enum.GetValues(typeof(T)).OfType&lt;object&gt;().Select(o =&gt; o.ToString()).ToArray();
  
              return new StandardValuesCollection(values);
          }
  
      }
  </code></pre>
  
  <p>I can then add a custom attribute to the property, referencing this TypeConverter, as below (typedConverterGenericType is the the type of TypedConverter with an enum generic argument)</p>
  
  <pre><code>CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(typeof(TypeConverterAttribute).GetConstructor(new Type[] { typeof(Type) }), new Type[] { typedConverterGenericType });
  
  propertyBuilder.SetCustomAttribute(attributeBuilder);
  </code></pre>
  
  <p>This works <strong>great</strong>, as long as the Enum in question is hardcoded: <code>AddTypeConverterAttribute(propertyBuilder, typeof(TypedConverter&lt;Fred&gt;));</code>. In the debugger, the attribute on the property gives me <code>{[System.ComponentModel.TypeConverterAttribute( ...</code>.</p>
  
  <p>However, when I use a dynamically built enum (that I have determined is generated properly in reflection) does not work:</p>
  
  <pre><code>   Type enumType = enumBuilder.CreateType();//This generates a proper enum, as I have determined in reflection
  
     Type converterType = typeof(TypedConverter&lt;&gt;);
  
     Type typedConverterType = converterType.MakeGenericType(enumType);
  
     AddTypeConverterAttribute(propertyBuilder, typedConverterType);
  </code></pre>
  
  <p>In the debugger, the attribute on the property now gives me <code>{System.Reflection.CustomAttributeData}</code>, and drilling into this, I have an error on the ConstructorArguments <code>... Mscorlib_CollectionDebugView&lt;System.Reflection.CustomAttributeData&gt;(type.GetProperties()[1].CustomAttributes).Items[4].ConstructorArguments' threw an exception of type 'System.IO.FileNotFoundException'</code> </p>
  
  <p>What am I doing wrong? How can I get the TypeConverter attribute set properly?</p>
  
  <p><strong>EDIT</strong>: In case someone wants to see how I add the attribute</p>
  
  <pre><code>private void AddTypeConverterAttribute(PropertyBuilder propertyBuilder, Type typedConverterGenericType)
  {
     CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(typeof(TypeConverterAttribute).GetConstructor(new Type[] { typeof(Type) }), new Type[] { typedConverterGenericType });
  
     propertyBuilder.SetCustomAttribute(attributeBuilder);        
  }
  </code></pre>
  
  <p><strong>EDIT2</strong></p>
  
  <p>Testing confirms it is an issue with the dynamically built enum - if I create the generic type with <code>Type typedConverterType = converterType.MakeGenericType(typeof(Fred));</code> it works fine.</p>
  
  <p><strong>EDIT 3</strong></p>
  
  <p>My test project is available <a href="http://purehumbug.com/files/PropertiesExample.zip" rel="nofollow">here</a>. It is reading some JSON from Resouces, and trying to generate a class whose type is described by that JSON. </p>
  
  <p>I am creating an instance of that class (<code>Activator.CreateInstance</code>) that will source a PropertyGrid. To get combo selection on that PropertyGrid, I am creating a Type, with a property attributed with TypedConverter, where T is an enum that describes the values in the combo selection. </p>
  
  <p>This works great for hardcoded enums, but not for programatically generated ones</p>