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 /
  • Help Room /
avatar image
0
Question by TheNoobieWaffle · Jun 06, 2016 at 05:07 AM · networkinghashtable

Hashtable Deserialization & How to create a reference variable to a field obtained through reflection

I'm using the LLAPI to make my own custom networking system. Going pretty good. I use serialized hashtables to transfer RPC data. I serialize it without issue, but upon recieveing the serialized hashtable, I get an error trying to deserialize it. I looked at https://msdn.microsoft.com/en-us/library/system.runtime.serialization.formatters.binary.binaryformatter%28v=vs.110%29.aspx and I'm following the same criteria, but I get this error:

SerializationException: Unexpected binary element: 0 System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObject (BinaryElement element, System.IO.BinaryReader reader, System.Int64& objectId, System.Object& value, System.Runtime.Serialization.SerializationInfo& info) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs:254) System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadNextObject (BinaryElement element, System.IO.BinaryReader reader) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs:130) 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:104) 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) NetworkMain.ReceiveMessages () (at Assets/NoobieNetworking/NetworkMain.cs:408) NetworkMain.Update () (at Assets/NoobieNetworking/NetworkMain.cs:123)

Here is my serialization (if this helps):

 Hashtable data = new Hashtable();
 data.Add( 0, "test" );
 
 byte error;
 byte[] buffer = new byte[1024];
 Stream stream = new MemoryStream( buffer );
 BinaryFormatter f = new BinaryFormatter();
 f.Serialize( stream, data );
         
 foreach ( int id in recipients ) {
     NetworkTransport.Send( localSocket, id, channelReliable, buffer, ( int )stream.Position, out error );
     LogNetworkError( error );
 }

Here is my deserialization:

 Stream stream = new MemoryStream( buffer );
 BinaryFormatter f = new BinaryFormatter();
 Hashtable tData = null;
 tData = ( Hashtable )f.Deserialize( stream );//LINE 408
 GameManager.gm.Log( "HASHTABLE DATA: " + tData[0] );

Comment
Add comment · Show 2
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 TheNoobieWaffle · Jun 04, 2016 at 01:08 AM 0
Share

I've also tried sending an empty hashtable, I get the same error. FYI, if that helps

avatar image TheNoobieWaffle · Jun 04, 2016 at 06:25 PM 0
Share

I have another question, and I dont want to wait 16 hours for moderator approval: Is it possible to set a reference variable to a field I obtained through reflection, given I know what game object contains that same class that the field is in?

For instance, theres a component (lets call it ScrComponent), and its on on gameObject (GameObj). That component in a C# class and contains the int32 field (intField). If I use reflection, like (like down below), can I create a reference variable to modify that variable directly as long as I still know what component it is a part of?

 int obtainedInt = GameObj.GetComponent().GetField( "intField" ).GetValue( scrComponent );

I want to directly access the field with a reference variable so I dont have to keep using reflection. How can this be accomplished?

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

59 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 avatar image avatar image avatar image

Related Questions

[PUN] All players control one object 0 Answers

issue with forcing spawn locations server controlling client spawn points 0 Answers

Updating matchmaker slots 1 Answer

How to call [Command] from client? 0 Answers

How to detect a client losing connection from the server using UNET 0 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