Click here to Skip to main content
12,997,060 members (75,795 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I've created a project with a generic gridview control which I use in every form.
public partial class _GenericGridViewControl<T> : UserControl

public partial class tblMerk_GridViewControl : _GenericGridViewControl<tblMerk>, IGenericGridViewControl

For type<T> I only use Linq dataclasses. It all worked great, until I accedently checked-out the project file in sourcesafe on my laptop and formatted my laptop. As a fix I had to undo-checkout the project-file on my computer and that's where the weird stuff began;

When I try to resize a custom control in the designer(any custom control in any form) the following error pops-up:
<br />
Type 'DataAccess.tblMerk' in Assembly 'DataAccess, Version=, Culture=neutral, PublicKeyToken=null' is not marked as serializable.<br />

Now I've searched google for this problem and I found out it has something to do with the designer wanting to serialize the control for some kind of caching, but it can't, cause my custom controls are not serializable, and will never be serializable. I also found out it might has something to do with a different error in some designer file which is masked by this error, but I don't know for sure that this is the cause here as my project compiles and workes great.

Please help me get my designer to start working for me again.

Thanks in advance, Willem
Posted 4-May-11 22:05pm
Updated 5-May-11 2:00am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

willempipi 5-May-11 6:35am
Thank you, it took some time but I found out the solution was to add these attributes to all properties that were of type<T>:


Apperantly the designer tries to serialize these properties and end up with the error.

public partial class _GenericGridViewControl<T> : UserControl // << Designer had no problems with this
where T : class, new()
public List<T> LoadedItems = new List<T>(); // << Here was the problem
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I suggest not to use generic controls. Marking a member as generic is OK, but marking the whole class as generic sounds like you will have lots of problems with the designer...

If you really want to use a generic control, then forget about the designer and add it manually in your .cs file.
willempipi 5-May-11 4:56am
Sorry, but this is a very very poor solution. My complete project consists of generic usercontrols to minimize the amount of programming. If I would listen to your solution I would have to reprogram my entire project, which already contains more then 1 year of work.

Also, this problem appeared just one day ago, with the check-out problem, before that, I never had any problems with the designer, so why should it not work now. [Edit] Though solved i'm still in the dark about this one. [/Edit]
Olivier Levrey 5-May-11 5:08am
Then I would say that your original design choices are wrong.

If somebody asked me "What do you think about creating generic controls", I would just answer "forget it" even before seeing your problem. The designer is very powerful but is limited in many situations and I would bet that dealing with generic controls is part of that limitations.

But you are free not to follow my advice. If you can fix that problem without recoding everything, it would be of course welcome.

Good luck.
willempipi 5-May-11 6:51am
I'm sorry for being so hard on you, but your "don't use generic usercontrols" answer is like saying to someone who is reparing a car-transmission: "Just don't use a transmission, cause its very hard to repair a transmission."
Olivier Levrey 5-May-11 7:33am
Don't be sorry, it's ok. It looks like you found a solution to your problem so everything is fine. I just gave my feelings about such a choice.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 5 May 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100