שתף באמצעות


Error PublicKeyToken is not marked as serializable

Question

Sunday, December 30, 2012 8:33 AM



Here is an error I keep getting I am getting this error in both Visual Studio 2010 and 2012

The only difference is that VS 2012 won't let me change any of the properties or even delete controls of the form.
In addition it's not allowing me to compile the project in VS 2012.

I get this error in VS 2010

the property 'obsticles' is coded like this...

    Public Property obsticles As List(Of PictureBox)
        Get
            Return _obsticles
        End Get
        Set(ByVal value As List(Of PictureBox))
            _obsticles = value
        End Set
    End Property
Dim _obsticles As New List(Of PictureBox)

Here is the project source...

All replies (9)

Wednesday, January 2, 2013 3:34 PM ✅Answered | 2 votes

I didn't download your project, but I'm guessing that the property "obsticles" is on a Control, but Control properties must be serializable types, or they must be hidden from the designer.

So you have two choices:  either hide the Obsticles property from the designer, or replace it with a custom collection that can be serialized.  If you want to be able to add pictureboxes to the user control via the properties grid in visual studio during design time, then you'll need to go the custom collection route and possibly provide custom editors.  If you will only modify the obsticles property via code and don't care about modifying the list in the designer, then simply hiding the property with attributes is probably best.

Here is an example of your property with the appropriate attributes to hide it from the designer:

Private _obsticles As New List(Of PictureBox)<System.ComponentModel.Browsable(False)><System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)>Public Property obsticles As List(Of PictureBox)    Get        Return _obsticles    End Get    Set(ByVal value As List(Of PictureBox))        _obsticles = value    End SetEnd Property 

Note that after making this change you may still have to delete and replace any current instances of this control on your form (or manually edit the resx file for the form to remove any entry for the control) depending on the current state of your project (it kind of sounds like there might have already been an instance of the control on the form when you added the obsticles property).  Try rebuilding and opening the form and see if it works.  If you still have errors, then go about trying to fix or replace the existing control instances.

Reed Kimble - "When you do things right, people won't be sure you've done anything at all"


Monday, December 31, 2012 6:46 AM

This project works without any error on my PC.  Maybe you need to repair your .NET framework...

Think again!


Monday, December 31, 2012 9:58 AM

It normally does. The error does not occur right away. 
Try to go to the main form and resize the 'game1' by dragging. That is the easiest way for me to recreate the error.


Monday, December 31, 2012 11:00 AM

It normally does. The error does not occur right away. 
Try to go to the main form and resize the 'game1' by dragging. That is the easiest way for me to recreate the error.

I'm sure this doesn't fix your problem, but I did notice that you aren't using "Option Strict On", which is a mistake. Turn Option Strict On, and watch how many errors it will find. I noticed it was around 10 different  errors.

If you want something you've never had, you need to do something you've never done.

Everyone should take the time to mark helpful posts and propose answers!

Answer an interesting question?
Create a wiki article about it!

My Technet Wiki Articles


Monday, December 31, 2012 11:25 AM

I just tried that, the problem still occurs, when you attempt to resize the control as I told you. I don't know how to force the recreation of the error any other way, but that error in 2012 will make it even not able to save or compile. It compiles in 2010 and saves after I click the ok button every time it comes up with the error. 


Monday, December 31, 2012 11:30 AM

I just tried that, the problem still occurs, when you attempt to resize the control as I told you. I don't know how to force the recreation of the error any other way, but that error in 2012 will make it even not able to save or compile. It compiles in 2010 and saves after I click the ok button every time it comes up with the error. 

Strange, I was getting the problem when I performed a build, so I didn't notice the resize problem until you mentioned. Hmm I'll look a little more.

If you want something you've never had, you need to do something you've never done.

Everyone should take the time to mark helpful posts and propose answers!

Answer an interesting question?
Create a wiki article about it!

My Technet Wiki Articles


Monday, December 31, 2012 11:34 AM

When you said that you were getting the error when you were performing the build that is what keeps happening that I am unable to recreate. Yet the same error is recreateable by resizing the control.


Thursday, January 3, 2013 12:30 AM

Wow that was exactly the problem! Thanks!

Dim Blondedude092 as SkypeUser


Tuesday, November 19, 2013 5:31 PM

It's ALIVE!!!!!

C#

[System.ComponentModel.Browsable(false)]
[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public List<dominio.gral.direccion>MisDirecciones
{
get { return misDirecciones; }
set { misDirecciones = value; }
}
</dominio.gral.direccion>