Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Aug 26, 2016 at 06:31 PM by TickTakashi for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by TickTakashi · Aug 25, 2016 at 08:54 PM · serializationstringbinaryformatterdeserialization

Using BinaryFormatter for deserialization - ArgumentException: method argument length mismatch

So i'm trying to serialize and deserialize a few basic classes, I get this very cryptic error:

 ArgumentException: method argument length mismatch
 System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, Boolean throwOnBindFailure) 

And I really have absolutely no idea why. My code contains no delegates, no reflection, nothing but basic data structures.

Any tips?

Here's the error in full.

 ArgumentException: method argument length mismatch
 System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, Boolean throwOnBindFailure) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Delegate.cs:226)
 System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Delegate.cs:276)
 System.Runtime.Serialization.SerializationCallbacks.Invoke (System.Collections.ArrayList list, System.Object target, StreamingContext context) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization/SerializationCallbacks.cs:110)
 System.Runtime.Serialization.SerializationCallbacks.RaiseOnDeserialized (System.Object target, StreamingContext contex) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization/SerializationCallbacks.cs:136)
 System.Runtime.Serialization.ObjectManager.RaiseOnDeserializedEvent (System.Object obj) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization/ObjectManager.cs:186)
 System.Runtime.Serialization.ObjectManager.RaiseDeserializationEvent () (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization/ObjectManager.cs:162)
 System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadNextObject (System.IO.BinaryReader reader) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs:147)
 System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectGraph (BinaryElement elem, System.IO.BinaryReader reader, Boolean readHeaders, System.Object& result, System.Runtime.Remoting.Messaging.Header[]& headers) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs:110)
 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.NoCheckDeserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/BinaryFormatter.cs:179)
 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/BinaryFormatter.cs:136)
 DataLoader.DeserializeObject (System.String str) (at Assets/Code/Title/DataLoader.cs:237)
 DataLoader+<LoadGameBinary>c__Iterator0.MoveNext () (at Assets/Code/Title/DataLoader.cs:43)
 UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image juicyz · Aug 25, 2016 at 10:58 PM 1
Share

Can you post your code so we can have a look at that?

avatar image Bunny83 · Aug 25, 2016 at 11:20 PM 1
Share

As you can see from the stacktrace the error is thrown inside the "Deserialize" method of the BinaryFormatter. So you most likely have something setup the wrong way. How do your classes look like?

You might have a class that you deserialize that has a method with one of these attributes:

  • OnSerializingAttribute

  • OnSerializedAttribute

  • OnDeserializingAttribute

  • OnDeserializedAttribute

However that method most likely has the wrong signature. It should have just a Strea$$anonymous$$gContext parameter. The BinaryFormatter will construct a multicast delegate out of all methods that have such an attribute. Since the error comes from "RaiseOnDeserialized" you most likely have the attribute "OnDeserialized" on a wrong method.

avatar image TickTakashi Bunny83 · Aug 26, 2016 at 06:30 PM 0
Share

That was it. Thanks a ton!

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

56 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

EndOfStreamException : Failed to read past end of stream 1 Answer

EndOfStreamException : Failed to read past end of stream 1 Answer

How to add strings in a list AND be able to save it and load it? Using playerpref OR serialization 2 Answers

Why has my BinaryFormatter stopped working? 2 Answers

how to deserialize json with arbitrary string keys using JsonUtility(unity c#)? 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges