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
2
Question by ChuckSaldana · Jan 24, 2011 at 04:33 PM · xmldatapathfilesystem

Problem with error: IOException: Sharing violation on path

I'm having the following error in the unity console:

IOException: Sharing violation on path /Users/carlos/_Personal/Development/Unity3d/B2BUnity1/Assets/Documents/Profiles.xml System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) 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.Xml.XmlTextWriter..ctor (System.String filename, System.Text.Encoding encoding) ProfileManager.StoreProfiles (System.Collections.ArrayList profilesList) (at Assets/Scripts/ProfileManager.cs:86) GUITouchScroll.OnGUI () (at Assets/Scripts/GUITouchScroll.cs:113)

And the code at ProfileManager.cs:86

public void StoreProfiles(ArrayList profilesList) {

      // Create a new file specified path
    XmlTextWriter textWriter = new XmlTextWriter(profilesPath, null); // 86 
     // Opens the document
     textWriter.WriteStartDocument();

Code at GUITouchScroll.cs:113

ProfileManager profileMan = plane.GetComponent("ProfileManager") as ProfileManager;
    profileMan.profilesPath = Application.dataPath + "/Documents/Profiles.xml";
profileMan.StoreProfiles(list);  //113  

Is it possible that using Applicaction.dataPath is causing the problem? or maybe is it something related to XmlTextWriter?

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

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by udev · Nov 01, 2011 at 05:02 PM

I encountered the "sharing violation" exception when running the editor in OS X but NOT when running in Windows 7. The error is ambiguous but it would appear that a stream is not being closed resulting in a conflict when you attempt to create a new reader/writer.

The solution is as follows:

 XmlWriterSettings settings = new XmlWriterSettings();
 settings.CloseOutput = true;
 using(XmlWriter writer = XmlWriter.Create(file.CreateText(), settings)){    
   //do work here
 }

The XmlWriterSettings.CloseOutput will guarantee that the stream is closed when your XmlStream is disposed. Hopefully that will solve your problems :)

source: stackoverflow

Comment
Add comment · Show 1 · 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 numberkruncher · Apr 11, 2012 at 06:41 PM 0
Share

Thanks for pointing out the cause of this issue. I simply closed my stream once I was done with the saving in my case.

avatar image
2

Answer by wer 34534sgd · Mar 11, 2014 at 08:35 PM

I got the same Problem, Solution:

close all Windows and programs that use your opened unity project, especially close Visual Studio, then it works wihtout the error message

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 tonytony · Oct 23, 2011 at 09:34 PM

Anyone solved this problem?

Thanks

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 standingguy · Mar 21, 2014 at 05:42 PM

I ran into this error recently and found that it had nothing to do with my actual file IO. It turned out that I had duplicate objects. As you could imagine, two objects both trying to open and write to a file ends in bad things. So as a troubleshooting step you may want to double check what objects you instantiate and which ones were added through the editor (created at startup). Be sure to remove objects from the editor that you plan to instantiate later.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Include a file to build - and keep it editable 0 Answers

Won't read files from directory on android - Windows works fine. 0 Answers

How to access Playerprefs xml file on Android 0 Answers

A node in a childnode? 1 Answer

Using JSON to get tree data into JavaScript objects 3 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