I'm creating a custom control that will work something along the lines of a ListView (Groups and items).
The control has groups and groups have items, so one could first create one group, then add one or more items to that group (under that groups properties).
I'm running into this error when I try to build my project:
Invalid Resx file.
Could not load type Widget.ListCategory, Widget, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null which is used in the .RESX file.
Ensure that the necessary references have been added to your project. Line 186, position 5. Widget C:\Users\mb.ITHOZTING\Dropbox\Widget\Widget\Form1.resx 186
I have tried quite a lot of different things, so you must excuse me, I can't remember all of them, but these are those I remember:
I have tried implementing the ISerializer interface, didn't really do anything to my recollection.
I have tried deleting the generated code in the .Resx file, and then reconfiguring the control. Didn't help.
This is the culprit from the error message:
[Serializable]
class ListCategory : ListItemBase
{
#region Properties
private List<ListItem> items = new List<ListItem>();
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor(typeof(ListItemCollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
public List<ListItem> Items
{
get { return items; }
set { items = value; }
}
#endregion
}
Now there's quite a few files and a good amount of code, so here's the whole project: https://www.dropbox.com/sh/zwz72dqm7vii78v/AACLjpy2DYZyQPxP_BBf0WTQa?dl=0
What steps are I'm supposed to take to fix this?
I have possibly found the solution, but I'm not 100% sure, as I feel it's been a bit unstable (not the solution, but the issue), so I won't mark this as the answer yet.
What I had to do though, was to add a TypeConverter for each class that was giving me issues.
E.g the first one was the ListCategory, then the other classes started acting up, and then I just had to follow the same procedure till it worked.
I mixed the TypeConverter together from two different articles on providing rich design-time support.
These are the links:
This is the resulting TypeConverter:
class GroupListConverter : TypeConverter
{
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
{
return TypeDescriptor.GetProperties(typeof(GroupList));
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destType)
{
if (destType == typeof(InstanceDescriptor))
return true;
return base.CanConvertTo(context, destType);
}
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(InstanceDescriptor))
{
System.Reflection.ConstructorInfo ci = typeof(GroupList).GetConstructor(System.Type.EmptyTypes);
return new InstanceDescriptor(ci, null, false);
}
return base.ConvertTo(context, culture, value, destType);
}
}