I'm sorry ifmy replysounded rude in any way, that was not my intention.
I cannot recall ever having custom controls that expose generic types through public properties. There are numerous issues reported to microsoft regarding generics and designer serialization. The short answer foundfor
this perticular issue is:
"The issue that you have reported is actually By Design. WinForms doesn't support generics at design-time. In next release, we'll consider to improve that while resources/schedule allows."I had to try this out my self and made a small test solution consisting of two projects, one class library and one win forms app. In the class libI defined a class "MyClass".In the win app I created a UserControl that exposed a property of the type
List<ClassLibrary1.MyClass>.
I put the UserControl on my Form1 and saved. No problem. I confirmed that everything was fine by opening the Form1.resx in a text editor, copying the Base64 data serialized for my generic property and created asimple ConsoleApp thatdeserialized the data, and the object from the deserialization was what I expected, a List<ClassLibrary1.MyClass>.
So, how to trigg the issue? Well, peoplestates that thisis a versoning issue so I went back to my 2-project solution andrebuilt
only the ClassLibrary1 assemblyand re-open the Form1 designer and, it crashed!
I find this very odd especially since I'm using a fixed assembly/fileversion for the ClassLibrary1 assembly. What's even more strange is that if a switch to my ConsoleApp and run it using the same Base64 data (note that the Form1.resx hasn't changed) but with the "new" ClassLibrary1.dll it works fine. So, why does the Form1 designer fail?
The designer throws the following error; "
Object of type 'ClassLibrary1.MyClass[]' cannot be converted to type 'ClassLibrary1.MyClass[]'."(When a generic list of T is serialized it will be stored to the stream as T[]. In my case this is ClassLibrary1.MyClass[]. )To meitseems that the designeris working with two different versions of the ClassLibrary1 assembly concurrently. I found both versions under "\Document and Settings\user\Local Settings\Application Data\Microsoft\VisualStudio\8.0\ProjectAssemblies (the directory that supports the WinForms designer).
Rebuilding the whole solution doesn't help either. Restarting VS is the only way.
Just to see if this is only related to generics I changed the property type in my UserControl from List<ClassLibrary1.MyClass> to just ClassLibrary.MyClass (i.e. no generics nor collection) and tried everything all over again. Rebuilding only the ClassLibrary1.MyClass assembly messes up the Form1 designer in the exact same way as with the generic property type. However, rebuilding the whole solution makes the Form1 designer work again without restating VS.
As of now my conclusion is that WinForms designer does not support generics, and if this is due to a bugor simply a limitation in the designer is hard to tell. Even though restarting VS makes it possible to use generics this would fast become a menace to any UI developer.
/Calle
- Still confused, but on a higher level -