"IOException: Sharing violation on path" on building a Unity project on Mac OS X with Facebook Unity SDK 5.1

facebook-unity-sdk

Solution

It seems the modified version of XCodeEditor, the Facebook SDK uses, doesn't close the StreamReader.

You should change these lines in Assets\Facebook\Editor\iOS\third_party\XCodeEditor-for-Unity\XCProject.cs from:

projectFileInfo = new FileInfo( Path.Combine( this.filePath, "project.pbxproj" ) );
string contents = projectFileInfo.OpenText().ReadToEnd();

to:

projectFileInfo = new FileInfo( Path.Combine( this.filePath, "project.pbxproj" ) );
StreamReader sr = projectFileInfo.OpenText();
string contents = sr.ReadToEnd();
sr.Close();

The modification is from the original XCodeEditor (https://github.com/dcariola/XCodeEditor-for-Unity).

Problem

I get an "IOException: Sharing violation on path" after importing the Facebook Unity SDK. The exception is thrown from FacebookPostprocess.cs:35, when the PostProcess tries to Save the modified Xcode project.

Original source