4

I am very new to Unity3d and tried to open an existing project. While playing it shows the following error.

Assets/Scripts/DataAccess.cs(39,30): error CS0117: System.IO.File' does not contain a definition forAppendAllText'

I dont have any idea about how to solve this. I get stuck over here.

It would be appreciating if anyone solve this problem.

Thanks in advance...

Andy
  • 8,432
  • 6
  • 38
  • 76
vinothp
  • 9,939
  • 19
  • 61
  • 103
  • It's been in .NET since at least 2 by the look of [the documentation](http://msdn.microsoft.com/en-us/library/system.io.file.appendalltext.aspx). Which version of Mono are you using? Is Monodroid a cut-down version of the framework like the .NET compact framework? – Rup Apr 12 '12 at 10:33
  • Thanks for your comments.. I have seen that documentation from that i understand i need .NET4. I am using Mono 2.8.2.Ya its cut-down version – vinothp Apr 12 '12 at 11:11
  • No, you don't need 4: I should have linked to one of the overload pages which say 'Supported in: 4, 3.5, 3.0, 2.0', plus it's also in the cut-down Silverlight run-time. If your cut-down version doesn't support it then I guess you'll have to code it up yourself: there might be a .NET implementation in the not-cut-down Mono source you can steal? – Rup Apr 12 '12 at 11:13
  • Sorry, Ya i have seen that it supports all versions. This is my code where it pointing. public DataAccess(string ConnectionString) { try{ SQLConn = new Mono.Data.Sqlite.SqliteConnection(ConnectionString); SQLConn.Open(); //Debug.Log ("Connected to SQLite db"); } catch (Exception e) { //Debug.Log(e.ToString()); File.AppendAllText(Application.persistentDataPath + "error.log", e.ToString()); } } – vinothp Apr 12 '12 at 11:18
  • If you could please sugest me any alternative to file.appendalltext to resolve this error..It would be more helpful.. – vinothp Apr 12 '12 at 11:29

2 Answers2

11

I ran into this, where no one else on my team could reproduce it.

We are targeting the iOS platform, and for some reason, my Build settings changed magically back to Web Player. Changing this BACK to iOS fixed the issue for me.

On Mac, I went to File ==> Build Settings...

The "Unity" icon was next to Web Player, so I switched it to iOS and hit the "Switch Platform" button. It reimported a bunch of stuff and, when it was done, the compiler error went away.

OnlineCop
  • 4,019
  • 23
  • 35
0

You can try File.AppendText:

using(StreamWriter sw = File.AppendText(
          Application.persistentDataPath + "error.log"))
{
    sw.Write(e.ToString());
}

That may not be the best way to do this but it should work. I don't know if AppendAllText includes an implicit newline - doesn't appear to from the docs - but you might want .WriteLine instead.

Rup
  • 33,765
  • 9
  • 83
  • 112
  • Thanks for your answer.. Actually i have tried that as well. It not seems to working.. AppendAllText is in docs http://msdn.microsoft.com/en-us/library/ms143356.aspx. check it here.. – vinothp Apr 12 '12 at 12:18
  • Sorry, I don't have any better ideas. When you say not working you mean not writing to the log, or throwing an exception, or something else? – Rup Apr 12 '12 at 12:42