InvalidCastException: Specified cast is not valid. (wrapper castclass) System.Object

Don’t use the binary formatter/serializer: it is insecure, it cannot be made secure, and it makes debugging very difficult, plus it actually will NOT prevent people from modifying your save data on their computers.

Beyond that, the complete error message contains everything you need to know to fix the error yourself.

Always start with the FIRST error in the list, as sometimes that error causes or compounds some or all of the subsequent errors.

The important parts of the error message are:

  • the description of the error itself (google this; you are NEVER the first one!)
  • the file it occurred in (critical!)
  • the line number and character position (the two numbers in parentheses)

All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.

This may be applicable too: some help to fix “Cannot implicitly convert type ‘Xxxxx’ into ‘Yyyy’:”

http://plbm.com/?p=263

Finally, if you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: Using code tags properly

1 Like