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 /
avatar image
0
Question by Smurfj3 · Mar 16, 2017 at 12:10 PM · androidunity 5dllassemblyframework

Unity android application custom dll problem

So I got something really weird going on, I made an application for android, when I start the application in unity everything works fine. However when I build it to my android device it works sometimes. How can a application work sometimes...

Anyhow ofcourse I did some debugging and it seems it sometimes get stuck on a reference that I have on a custom dll imported in the asset folder. I have a server running that sends a List of custom objects to my unity application, in order to deserialize it properly I had to import my server application as dll into unity which I did. Now when I debug it with adb logcat, I can see it sometimes gets stuck on deserializing the object sent from the server but not always. I can start the app like 50 times and like 1 out of 50 it will work.

I have tried the following things:

  • I have tried to change the API compatibility level from .net 2.0 subset to just .net 2.0

  • on my dll build I changed the target framework to Unity 3.5 .net full base class libraries

  • I have debugged my application running it on pc and no errors ever occur

The problem is not the tcpclient or server, because the connection is still there eventho it doesn't receive the custom object properly.

I really about to give up, I don't understand how it works sometimes, other times it doesn't.

------edit------

I should probably mention the only warning I have in unity console is the following:

Serialization depth limit 7 exceeded at 'Android_ChatRoomController::RunServer.lstclients'. There may be an object composition cycle in one or more of your serialized classes.

Android_ChatRoomController is the custom dll.

-----EDIT actual Logcat error:

TypeLoadException: Could not load type 'System.Collections.Generic.List`1[[Android_Cha I/Unity (18811): at System.Type.GetType (System.String typeName, Boolean throwOnError) [0x00000] in :0 I/Unity (18811): at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadTypeMetadata (System.IO.BinaryReader reader, Boolean isRuntimeObject, Boolean hasTypeInfo) [0x00000] in :0 I/Unity (18811): at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectInstance (System.IO.BinaryReader reader, Boolean isRuntimeObject, Boolean hasTypeInfo, System.Int64& objectId, System.Object& value, System.Runtime.Serialization.SerializationInfo& info) [0x00000] in :0 I/Unity (18811): at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObject (BinaryElement element, System.IO.BinaryReader reader, System.Int64& objectId, System.Object& value, System.Runtime.Serialization.SerializationInfo& info) [0x00000] in :0

Comment
Add comment · Show 5
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 NerdClown · Mar 16, 2017 at 01:21 PM 0
Share

Since both the warning and the error seem to be related to serialization, I guess that's where the problem is. Never had the problem myself so I don't really know, but from what I could find it seems that there is an issue with what unity serializes.

I think the first post here could be interesting for you:

https://forum.unity3d.com/threads/4-5-serialization-depth.248321/

And if it is indeed the case that private/protected fields are serialized, you would quite feasibly get under a depth of seven. Unity would give up, the serialized object would be invalid and fail would ensue.

Anyhow, if you want to test if this is indeed your issue, you could throw in [NonSerialized] everywhere in your serialized object and then remove them to little by little find out what makes the problem occur.

avatar image Smurfj3 · Mar 16, 2017 at 01:29 PM 0
Share

@nerdclown the warning about serialization depth shouldn't have any influence on the app tho, so I doubt thats the reason, I just now converted the dll target framework from Unity 3.5 .net full base class libraries to .net 2.0, still no change tho, it works sometimes, and other times it doesn't.

I seriously have no idea what is going on, the only thing I know it has to do with the serialization and deserialization.

avatar image NerdClown Smurfj3 · Mar 16, 2017 at 01:46 PM 1
Share

Well, not knowing your project, which classes you serialize and so on, I still think that could be the issue. I don't see how that warning shouldn't have any influence on the app.

From the post I linked:

Fact #1; Unity stops serializing object after 7 levels of depth. Beyond that, it assumes it's an error - a reference dependency loop. Before 4.5, Unity simply didn't tell you anything and silently erased your data, now it pops an error.

According to your post this exact thing happens, and something is not serialized properly.

Your error call stack shows that the error occurs somewhere in the object reader, which might be the object that was not serialized properly.

Anyhows, if you can make the same problem occurs with a real simple class or everything set to non-serialized, you'll know for sure that I'm mistaken!

avatar image Smurfj3 NerdClown · Mar 16, 2017 at 01:51 PM 0
Share

This is the class its about

 namespace Android_ChatRoomController
 {
     [Serializable]
     class Clients
     {
         public string ClientName;
         [NonSerialized]
         public TcpClient ClientSocket;
     }
 }

I don't understand how to make this better

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Smurfj3 · Mar 16, 2017 at 02:54 PM

Well I got it fixed, I still don't understand why this fixed it but basically what I used to do is have a server application which I turned completely into a dll and imported it into unity so I could deserialize some of the classes in the server application. What I did now, is just made a class library of the classes that actually matter to the unity project and left out the rest of the server application.

So now it seems to work, tried it 3 times and worked every time and the second thing that is awesome about it, is that the dll is smaller :)

Comment
Add comment · Share
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

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

160 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 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 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

How to take a value from Regedit using .NET 3.5? 0 Answers

in Unity 5, how can I get/set an asset's AssetBundle assignment via scripting? 1 Answer

C# assembly and dll files are not being loaded. 2 Answers

Cannot get objects to appear on client screen using new network system on Android wifi 0 Answers

Unity 5.3 In-App Purchase Error 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