"Failed to generate" ... "is not marked as serializable" errors for no reaso
You may occasionally receive repeated dialog boxes saying that Visual Studio was unable to generate code for an object because it"is not marked as serializable".
Whilst this may be legitamate in some situations where serialisation is required, such as where the object is passed to a web service, in other situations it is a bug in Visual Studio. In my case it was a public collection (List<>) of a simple class (just two properties).
Marking the object as serializable will not make the message go away, and neither will recompiling (which will display this message everytime the compiler encounters the object).
The solution is to comment out the object and all references to it, close Visual Studio (if you don't you will continue to receive the error even though the object no longer exists!), re-open the project and compile it. The problem should have gone away.
You can then uncomment the object and it's references and the recompile.The project will be exactly the same as it was but the error will have gone.
I'm not sure at to the cause of the error, but in my case it happened after I refactored a public collection field to be a public collection property, so I suspect that the refactoring process corrupted a generated file which VS then decided not to recompile even when the object implementation changed or even when it was removed entirely.

