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
1
Question by simubrett · Mar 13, 2012 at 12:40 AM · c#iosio

Sharing Violation on iOS

For my game, I'm trying to save the player's progress to a file, and later load from it. I'm doing this by serializing an object that holds the progress. Both saving and loading are working fine from the editor, but when I try an iOS build, I get a sharing violation on the path I'm trying to write to upon saving.

Here's my code:

 string saveFilePath = Path.Combine(Application.persistentDataPath, "progress.txt");

 FileStream stream = File.Create(saveFilePath);
 BinaryFormatter formatter = new BinaryFormatter();
 formatter.Serialize(stream, ProgressStore);
 stream.Close();

ProgressStore is my object that gets serialized. Through debug messaging, I see that the File.Create is throwing the IOException, but I simply can't figure out why. I've also tried File.Open with various FileMode options, and File.CreateText.

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

2 Replies

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

Answer by simubrett · Mar 15, 2012 at 05:06 AM

Well, I found that if I trade out the BinaryFormatter for an XmlSerializer, it all just works. Apparently there's a problem with .NET's JIT on iOS that was causing it to throw the Sharing Violation.

Ended up changing some stuff around to boot, so the working code looks like this:

 using (MemoryStream stream = new MemoryStream()) {
   XmlSerializer progressSerializer = new XmlSerializer(typeof(ProgressObject));
   progressSerializer.Serialize(stream, ProgressStore);
   using (FileStream fileWriter = File.Create(saveFilePath)) {
     byte[] originalData = stream.GetBuffer();
     fileWriter.Write(originalData,0,originalData.Length);
     fileWriter.Close();
   }
 }

And yes, this exact same snippet crashes (on iOS only) if you change the XmlSerializer to a BinaryFormatter.

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

Answer by ickydime · Nov 17, 2015 at 07:38 PM

I found this link helpful for explaining how to get the BinaryFormatter to work as an alternative to using the XMLSerializer:

http://answers.unity3d.com/questions/30930/why-did-my-binaryserialzer-stop-working.html

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

WebCamTexture IOS crashing? 1 Answer

[Solved] Is it okay if we change transform.position on a kinematic rigid body which also does not use Gravity? 2 Answers

C# How can I get unity game to not go past title screen if there is no internet connection on iOS device 1 Answer


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