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 talaxet · May 22, 2016 at 04:42 PM · javascriptsystem.iosharing

System.IO sharing error despite closing the read and write

system.io is giving a sharing file error when using these two functions (not simultaneously) here are the two functions that handle saving and loading from what i can tell it looks to be something to do with loading because it can load fine but when trying to save after a load it will give a sharing error but i haven't tested it the other way around, i know the code is long but i wanted to include both functions because the error code (from what i can see) doesn't tell much info about what line caused the error but rather the error within System.IO itself there are a few lines in the error that are associated with the saving function though but i think its referring to what it was calling rather than the saving function leaving its stream Writer open and not closing it

 function saveGameList ()
 {
     var sw : StreamWriter = new System.IO.StreamWriter(Application.dataPath + "/" + "games.list");  //opened to same directory
     for(var i = 0; i < names.length; i++)
     {
         sw.WriteLine(fitToFileFormat(i)); //loops through slots and combines info in 7 different arrays to 1 variable to look like "hello-1-1-1-1-1-1"
     }
     sw.WriteLine("#"); //signals the array info is over
     sw.WriteLine(core.money); //writes player variables
     sw.WriteLine(core.compName); //writes player variables
     sw.WriteLine(core.playerName); //writes player variables
     sw.Close();    //both read and write are being closed
 }
 
 function loadGameList ()
 {
     var sr : StreamReader = new System.IO.StreamReader(Application.dataPath + "/" + "games.list"); //opened to same directory
     var found = false;
     for(var i = 0; i < 15 && found == false; i++)
     {
         var line = sr.ReadLine();
         Debug.Log(line); 
         if(line == "#") //checks to see if the array info is over then sets the player variables after the for loop
         {
             found = true;
         }
         else
         {    
             var game = line.Split("-"[0]);
             addNewGame(game[0],parseInt(game[1]),parseInt(game[2]),parseInt(game[3]),parseInt(game[4]),parseInt(game[5]),parseInt(game[6])); //adds the info to the 7 arrays described at the top
         }
     }
     core.money = parseInt(sr.ReadLine()); //sets player variables
     core.compName = sr.ReadLine(); //sets player variables
     core.playerName = sr.ReadLine(); //sets player variables
     sr.Close(); //both read and write are being closed
 }

here is the full error that unity gives

 System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/FileStream.cs:320)
 System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share)
 (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
 System.IO.StreamWriter..ctor (System.String path, Boolean append, System.Text.Encoding encoding, Int32 bufferSize) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/StreamWriter.cs:124)
 System.IO.StreamWriter..ctor (System.String path)
 (wrapper remoting-invoke-with-check) System.IO.StreamWriter:.ctor (string)
 CoreMechanic.saveGameList () (at Assets/CoreMechanic.js:108)
 CoreMechanic.addNewGame (System.String name, Int32 platform, Int32 genre, Int32 style, Int32 client, Int32 initialCost, Int32 weeklyCost) (at Assets/CoreMechanic.js:43)
 gameCreateMaster.createGame () (at Assets/gameCreateMaster.js:26)
 UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:144)
 UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:621)
 UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:756)
 UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:53)
 UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35)
 UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44)
 UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:52)
 UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:269)
 UnityEngine.EventSystems.EventSystem:Update()

ive tried alot of techniques to help with it like .flush() and .Dispose() but its still gives the sharing error

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How do I make it so players can't edit the file but the game can? File.CreateText 2 Answers

How would I transfer these into PlayerPrefs? 0 Answers

Setting Scroll View Width GUILayout 1 Answer

Date File was edited? 0 Answers

Can someone help me fix my Javascript for Flickering Light? 6 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