2
votes

I created a usercontrol in vb.net winforms that has a Dictionary as property. I am getting the following error message:

Error 1 Invalid Resx file. Could not load type System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[MIDAS.CheckedComboBoxItem, MIDAS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 which is used in the .RESX file. Ensure that the necessary references have been added to your project. Line 135, position 5. C:\Users\desig.nizam\documents\visual studio 2010\Projects\MIDAS\MIDAS\FGEO\FGEO.resx 135 5 MIDAS

I am using this control in some forms successfully, but not in the new ones. If I delete the controls of the forms I can compile without error.

I googled a solution and could find a lot of related topic, but none of them helped me to solve my case.

1
it sounds like a designer serialization issue. what is in the dictionary and can you show the code exposing it as a property.. why a dictionary vs a collection as a property? - Ňɏssa Pøngjǣrdenlarp
That is exactly this. The topic stackoverflow.com/questions/8158419/cannot-add-control-to-form showed me the solution for this problem. - Nizam
you will have to change the Dictionary to a NET Collection - NOT the VB collection - then work on serializing whatever goes into the collection mostly the Attributes mentioned in the link, but also possibly a TypeConverter. The issue is that VS cant serialize it, so it is storing info in the RESX file (probably Base64) but cannot deserialize it. - Ňɏssa Pøngjǣrdenlarp

1 Answers

3
votes

The solution to this problem is to set this attribute to Dictionary:

<DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)>

The same problem was already discussed in

Cannot Add control to form