Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
3
Question by Leniaal · Jan 26, 2016 at 12:25 PM · filexmlsystem.io

UnauthorizedAccessException: Access to the path is denied

Hello,

I have a problem saving my XML file;

 using System.Xml.Serialization;
 using System.IO;
 using System.Collections.Generic;
 
 [XmlRoot("BuildedObjectCollection")]
 public class BuildedObjectContainer {
 
     [XmlArray("BuildedObjects")]
     [XmlArrayItem("BuildedObject")]
     public List<BuildedObject> buildedObjects;
 
     public void Save(string path)
     {
         var serializer = new XmlSerializer(typeof(BuildedObjectContainer));
         using (var stream = new FileStream(path, FileMode.Create))
         {
             serializer.Serialize(stream, this);
         }
     }
 }

The save is called here

         public void Save()
         {
             Debug.Log(Application.dataPath);
             boContainer.Save(Application.dataPath);
         }
 

The full error I get is

 UnauthorizedAccessException: Access to the path 'D:/Unity Projects/RenewedTTD/Assets' is denied.
 
 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:259)
 System.IO.FileStream..ctor (System.String path, FileMode mode)
 (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode)
 BuildedObjectContainer.Save (System.String path) (at Assets/Scripts/BuildedObjectContainer.cs:15)
 Build.Save () (at Assets/Scripts/Build.cs:107)
 UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:149)
 UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:626)
 UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:766)
 UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:54)
 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()
 

I've tried many things

  • Turned off Windows Defender

  • Used FileMode.CreateNew

  • Application.persistentDataPath

  • Made sure all maps weren't Read Only

  • Changed path to root C:\

  • Ran Unity as admin

All to no avail, I'm with the hands in my hair here. Could someone help me out?

Comment
Add comment · Show 3
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 coolraiman · Jan 26, 2016 at 02:12 PM 0
Share

did you try to run unity as ad$$anonymous$$istrator?

it is the only thing missing from your list of stuff you tried

avatar image Leniaal coolraiman · Jan 26, 2016 at 03:23 PM 0
Share

I have indeed tried to do so, forgot to put it in. But this also didn't help.

avatar image BackslashOllie · Jan 26, 2016 at 06:39 PM 1
Share

This is usually down to Antivirus software on your computer. Do you have any other AV software on your computer? $$anonymous$$cAfee, Norton, etc?

4 Replies

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

Answer by Leniaal · Jan 27, 2016 at 05:42 AM

I'm sorry I think I was a bit too tired when I asked this question, now that I looked at the code a bit clearly It's pretty obvious. At no point did I mention the actual name of the XML file I wanted to save.

 boContainer.Save(Path.Combine(Application.persistentDataPath, "objects.xml"));

Is what solved my problem. Hope I can help future overworked programmers :)

Comment
Add comment · Show 5 · 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 coolraiman · Jan 29, 2016 at 01:41 PM 0
Share

haha, happened to me to posted a question on stack overflow about somes trange bug in advanced reflection technique in the end, i just switched 2 paramaters by accident

avatar image ModLunar · Jun 23, 2017 at 07:08 PM 0
Share

Lol as silly as this sounds, my goodness your answer saved me. I was trying to a save a new file without even giving the file name, I just had the directory. I'm so glad it was so simple.. thank you.

avatar image _Mathias · Aug 27, 2017 at 09:41 PM 0
Share

Thank you, obvious but you also saved me, and I'm not the only one for sure. Thanks for posting the solution.

avatar image dan_cmj · Sep 20, 2019 at 09:52 PM 0
Share

This fixed the issue for me. Thank you!

avatar image kuro_sk · Feb 12, 2021 at 10:24 AM 0
Share

At no point did I mention the actual name of the X$$anonymous$$L file I wanted to save.

I did(n't do) something similar, and went to google straight away. Solved my problem. Thanks.

avatar image
0

Answer by codeguyross1 · Apr 05, 2017 at 09:28 PM

In order to correct the unauthorized user, I manually create a temp file and write to that. You dont have to disable any permissions that way.

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 ahmetala · Jun 07, 2020 at 06:01 PM

Don't make the path the drive.Mine path was D:/ and it occured problem.When I changed the root to D:/Programs my problem had been solved.

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 cwk17 · Jun 28, 2021 at 03:30 PM

haha, awesome, just did the same and I wasn't tired at all. So thanks for that... ;)

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

11 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

Related Questions

Missing additional configuration xml files after build 0 Answers

How to retrieve XML path in standalone version 1 Answer

Is there a way to encrypt/lock a File.CreateText file? (its my highscore) 1 Answer

Write to xml file in after build 0 Answers

How do I make it so players can't edit the file but the game can? File.CreateText 2 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