Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 hurjm1006 · Aug 07, 2020 at 12:30 PM · assetbundleil2cppbinaryformatterdeserialization

Android IL2CPP bulid crash MemoryStream deserialization

Hello! I'm developing casual game for Android and about to release first version.

But I stuck in terrible situation.

Google demand for 64bit apk, so I build as IL2CPP.

I get assetbundle from web server and it contains some binary data.

For binary data, I convert it as TextAsset.

Below is that code.

 private IEnumerator GetAssetBundle()
     {
         UnityWebRequest www = UnityWebRequest.Get(hNetworkManager.serverURL);
         yield return www.SendWebRequest();
 
         if (www.isNetworkError || www.isHttpError)
         {
             Application.Quit();
         }
         else
         {
             string assetBundleDirectory = Application.persistentDataPath + "/AssetBundle";
             string serialDataPath = Application.persistentDataPath + "/SerialData";
 
             if (!Directory.Exists(assetBundleDirectory))
                 Directory.CreateDirectory(assetBundleDirectory);
             if (!Directory.Exists(serialDataPath))
                 Directory.CreateDirectory(serialDataPath);
 
             TextAsset[] textAssets;
             AssetBundle assetBundle;
             hLevel.SerialData[] serialDatas;
             MemoryStream memoryStream;
             BinaryFormatter formatter;
 
             var studio = Instantiate(m_thumbnailStudio);
 
             byte[] data = new byte[www.downloadHandler.data.Length - head];
             System.Array.Copy(www.downloadHandler.data, head, data, 0, data.Length);
 
             File.WriteAllBytes(Path.Combine(assetBundleDirectory, "levels.unity3d"), data);
 
             assetBundle = AssetBundle.LoadFromFile(Path.Combine(assetBundleDirectory, "levels.unity3d"));
 
             if (assetBundle == null)
             {
                 //Debug.Log("Failed to load AssetBundle!");
                 yield break;
             }
 
             textAssets = assetBundle.LoadAllAssets<TextAsset>();
             serialDatas = new hLevel.SerialData[textAssets.Length];
 
             memoryStream = new MemoryStream();
             formatter = new BinaryFormatter();
             for (int i = 0; i < textAssets.Length; ++i)
             {
                 memoryStream.Write(textAssets[i].bytes, 0, textAssets[i].bytes.Length);
                 memoryStream.Position = 0;
                 serialDatas[i] = (hLevel.SerialData)formatter.Deserialize(memoryStream);
                 memoryStream.SetLength(0);
             }
             memoryStream.Close();
 
             var lastThemeColor = hColorManager.current.curColor;
             for (int i = 0; i < serialDatas.Length; ++i)
                 studio.SaveThumbnail(serialDatas[i]);
             hColorManager.current.SetTheme(lastThemeColor, true);
             hSharedData.Initialize(serialDatas);
             _loading.FirstLoading();
             #endregion
         }
     }


Up there "serialDatas[i] = (hLevel.SerialData)formatter.Deserialize(memoryStream);" line occur exception like this. alt text and build setting. alt text I also test Mono version and it worked properly.

I have no idea to solve this. PLEASE SOMEBODY HELP ME!

cv.png (59.0 kB)
a.png (144.3 kB)
Comment
Add comment · Show 4
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 JoshPeterson · Aug 11, 2020 at 11:28 AM 0
Share

Does this work with Android AR$$anonymous$$v7 (32-bit) builds with IL2CPP? Or is the problem only with 64-bit builds?

avatar image hurjm1006 JoshPeterson · Aug 11, 2020 at 12:51 PM 0
Share

Yes, exactly same exception.

avatar image JoshPeterson hurjm1006 · Aug 11, 2020 at 12:57 PM 0
Share

Can you submit this project with a bug report? This is not something we've seen before.

Show more comments

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

136 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

Related Questions

Using BinaryFormatter for deserialization - ArgumentException: method argument length mismatch 0 Answers

How to import the object from server to unity 2 Answers

[C#] Deserialization fails in Web Player 1 Answer

C# BinaryFormatter Deserialization Issues 1 Answer

Binary file Deserialize to list? 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