• 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 Cdawg_1999 · Oct 26, 2017 at 03:04 AM · score systemdata storagescoreboard

Serialization of an object in unity causing IO Exception Sharing Violation At Path

Hello all, I am having intense difficulty with my persistent score keeper. I am attempting to save a custom object of type ScoreList which contains only a list of type Score. I am then serializing this ScoreList.

 using System.Collections;
 using System.Collections.Generic;
 using System.IO;
 using System.Runtime.Serialization.Formatters.Binary;
 using UnityEngine;
 
 public class FileCreator{
     string fileName;
     public ScoreList data;
     FileStream file;
     public FileCreator(string fileName)
     {
         this.fileName = Path.Combine(Application.persistentDataPath,fileName+".dat");
         /*if(!File.Exists(this.fileName)) {
             file = File.Create(this.fileName);
             file.Close();
         }*/
     }
     public void SerializeData()
     {
         file = File.Open(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
         BinaryFormatter bf = new BinaryFormatter();
         bf.Serialize(file, data);
         file.Close();
         file.Dispose();
     }
     public void DeserializeData()
     {
         file = File.Open(fileName, FileMode.OpenOrCreate, FileAccess.Read);
         BinaryFormatter bf = new BinaryFormatter();
 
         data = (ScoreList)bf.Deserialize(file);
         file.Close();
         file.Dispose();
         
     }
 }
 

I am getting an error at this line file = File.Open(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);

The error is: IOException: Sharing violation on path C:\Users\Cameron\AppData\LocalLow\Wonderful3204\ToTheBeatVR\scoreinfo.dat (Shortened)

Does anybody have any ideas? Can I not serialize a list? Both the list and the Score classes are listed as serializable.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Tourist · Oct 26, 2017 at 07:21 AM

Your file is opened somewhere else while you try to serialize it.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

74 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

Related Questions

Score not increasing after killing 1 enemy 1 Answer

Highscore with points and time 1 Answer

How to alter c# script from a script in a different scene (i.e. display score in different scene) 2 Answers

Add point on click of cube? 1 Answer

Ive been trying to get a score counter to work for 2 weeks please help. 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges